mirror of
https://github.com/typst/typst
synced 2025-08-19 17:38:32 +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);
|
||||
output.push(HtmlNode::text(quote, child.span()));
|
||||
} 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>() {
|
||||
let locator = locator.next(&elem.span());
|
||||
|
@ -196,7 +196,7 @@ pub fn collect<'a>(
|
||||
let quote = quoter.quote(before, "es, double);
|
||||
collector.push_text(quote, styles);
|
||||
} else {
|
||||
collector.push_text(if double { "\"" } else { "'" }, styles);
|
||||
collector.push_text(SmartQuotes::fallback(double), styles);
|
||||
}
|
||||
} else if let Some(elem) = child.to_packed::<InlineElem>() {
|
||||
collector.push_item(Item::Skip(LTR_ISOLATE));
|
||||
|
@ -89,11 +89,7 @@ pub struct SmartQuoteElem {
|
||||
|
||||
impl PlainText for Packed<SmartQuoteElem> {
|
||||
fn plain_text(&self, text: &mut EcoString) {
|
||||
if self.double.as_option().unwrap_or(true) {
|
||||
text.push_str("\"");
|
||||
} else {
|
||||
text.push_str("'");
|
||||
}
|
||||
text.push_str(SmartQuotes::fallback(self.double.as_option().unwrap_or(true)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -305,6 +301,11 @@ impl<'s> SmartQuotes<'s> {
|
||||
pub fn close(&self, double: bool) -> &'s str {
|
||||
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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user