Deduplicate fallback smart quotes (#6747)

This commit is contained in:
Laurenz 2025-08-12 16:05:34 +02:00 committed by GitHub
parent 1e1d943d9d
commit 57f85eb4fd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 7 deletions

View File

@ -89,7 +89,7 @@ fn handle(
let quote = quoter.quote(before, &quotes, 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());

View File

@ -196,7 +196,7 @@ pub fn collect<'a>(
let quote = quoter.quote(before, &quotes, 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));

View File

@ -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.