mirror of
https://github.com/typst/typst
synced 2025-08-20 09:49:02 +08:00
Deduplicate fallback smart quotes (#6747)
This commit is contained in:
parent
1e1d943d9d
commit
57f85eb4fd
@ -89,7 +89,7 @@ fn handle(
|
|||||||
let quote = quoter.quote(before, "es, double);
|
let quote = quoter.quote(before, "es, double);
|
||||||
output.push(HtmlNode::text(quote, child.span()));
|
output.push(HtmlNode::text(quote, child.span()));
|
||||||
} else {
|
} else {
|
||||||
output.push(HtmlNode::text(if double { '"' } else { '\'' }, child.span()));
|
output.push(HtmlNode::text(SmartQuotes::fallback(double), child.span()));
|
||||||
}
|
}
|
||||||
} else if let Some(elem) = child.to_packed::<FrameElem>() {
|
} else if let Some(elem) = child.to_packed::<FrameElem>() {
|
||||||
let locator = locator.next(&elem.span());
|
let locator = locator.next(&elem.span());
|
||||||
|
@ -196,7 +196,7 @@ pub fn collect<'a>(
|
|||||||
let quote = quoter.quote(before, "es, double);
|
let quote = quoter.quote(before, "es, double);
|
||||||
collector.push_text(quote, styles);
|
collector.push_text(quote, styles);
|
||||||
} else {
|
} else {
|
||||||
collector.push_text(if double { "\"" } else { "'" }, styles);
|
collector.push_text(SmartQuotes::fallback(double), styles);
|
||||||
}
|
}
|
||||||
} else if let Some(elem) = child.to_packed::<InlineElem>() {
|
} else if let Some(elem) = child.to_packed::<InlineElem>() {
|
||||||
collector.push_item(Item::Skip(LTR_ISOLATE));
|
collector.push_item(Item::Skip(LTR_ISOLATE));
|
||||||
|
@ -89,11 +89,7 @@ pub struct SmartQuoteElem {
|
|||||||
|
|
||||||
impl PlainText for Packed<SmartQuoteElem> {
|
impl PlainText for Packed<SmartQuoteElem> {
|
||||||
fn plain_text(&self, text: &mut EcoString) {
|
fn plain_text(&self, text: &mut EcoString) {
|
||||||
if self.double.as_option().unwrap_or(true) {
|
text.push_str(SmartQuotes::fallback(self.double.as_option().unwrap_or(true)));
|
||||||
text.push_str("\"");
|
|
||||||
} else {
|
|
||||||
text.push_str("'");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -305,6 +301,11 @@ impl<'s> SmartQuotes<'s> {
|
|||||||
pub fn close(&self, double: bool) -> &'s str {
|
pub fn close(&self, double: bool) -> &'s str {
|
||||||
if double { self.double_close } else { self.single_close }
|
if double { self.double_close } else { self.single_close }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the fallback "dumb" quotes for when smart quotes are disabled.
|
||||||
|
pub fn fallback(double: bool) -> &'static str {
|
||||||
|
if double { "\"" } else { "'" }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An opening and closing quote.
|
/// An opening and closing quote.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user