Render opening smart quote after another opening quote of a different type (#1559)
This commit is contained in:
parent
b59b8bfb35
commit
3fcb5ea73c
@ -642,7 +642,7 @@ fn collect<'a>(
|
||||
};
|
||||
|
||||
if let Some(last) = full.chars().last() {
|
||||
quoter.last(last);
|
||||
quoter.last(last, child.is::<SmartQuoteElem>());
|
||||
}
|
||||
|
||||
spans.push(segment.len(), child.span());
|
||||
|
@ -66,6 +66,8 @@ pub struct Quoter {
|
||||
expect_opening: bool,
|
||||
/// Whether the last character was numeric.
|
||||
last_num: bool,
|
||||
/// The previous type of quote character, if it was an opening quote.
|
||||
prev_quote_type: Option<bool>,
|
||||
}
|
||||
|
||||
impl Quoter {
|
||||
@ -75,13 +77,17 @@ impl Quoter {
|
||||
quote_depth: 0,
|
||||
expect_opening: true,
|
||||
last_num: false,
|
||||
prev_quote_type: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Process the last seen character.
|
||||
pub fn last(&mut self, c: char) {
|
||||
pub fn last(&mut self, c: char, is_quote: bool) {
|
||||
self.expect_opening = is_ignorable(c) || is_opening_bracket(c);
|
||||
self.last_num = c.is_numeric();
|
||||
if !is_quote {
|
||||
self.prev_quote_type = None;
|
||||
}
|
||||
}
|
||||
|
||||
/// Process and substitute a quote.
|
||||
@ -92,8 +98,16 @@ impl Quoter {
|
||||
peeked: Option<char>,
|
||||
) -> &'a str {
|
||||
let peeked = peeked.unwrap_or(' ');
|
||||
if self.expect_opening {
|
||||
let mut expect_opening = self.expect_opening;
|
||||
if let Some(prev_double) = self.prev_quote_type.take() {
|
||||
if double != prev_double {
|
||||
expect_opening = true;
|
||||
}
|
||||
}
|
||||
|
||||
if expect_opening {
|
||||
self.quote_depth += 1;
|
||||
self.prev_quote_type = Some(double);
|
||||
quotes.open(double)
|
||||
} else if self.quote_depth > 0
|
||||
&& (peeked.is_ascii_punctuation() || is_ignorable(peeked))
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 76 KiB After Width: | Height: | Size: 79 KiB |
@ -60,3 +60,9 @@ He's told some books contain questionable "example text".
|
||||
"She suddenly started speaking french: #text(lang: "fr")['Je suis une banane.']" Roman told me.
|
||||
|
||||
Some people's thought on this would be #[#set smartquote(enabled: false); "strange."]
|
||||
|
||||
---
|
||||
// Test nested double and single quotes.
|
||||
"'test statement'" \
|
||||
"'test' statement" \
|
||||
"statement 'test'"
|
||||
|
Loading…
x
Reference in New Issue
Block a user