From cc210bf794263b4efe77c35137b3f3f992000708 Mon Sep 17 00:00:00 2001 From: Lance Lafontaine Date: Sat, 24 Jun 2017 21:51:17 -0400 Subject: [PATCH] Fixes some bugs with detection of inline code --- second-edition/tools/src/bin/convert_quotes.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/second-edition/tools/src/bin/convert_quotes.rs b/second-edition/tools/src/bin/convert_quotes.rs index be9e9c0cd..587f736ce 100644 --- a/second-edition/tools/src/bin/convert_quotes.rs +++ b/second-edition/tools/src/bin/convert_quotes.rs @@ -13,11 +13,15 @@ fn main () { for line in buffer.lines() { - // check if inside code block + if line.is_empty() { + is_in_inline_code = false; + } if line.starts_with("```") { is_in_code_block = !is_in_code_block; } if is_in_code_block { + is_in_inline_code = false; + is_in_html_tag = false; write!(io::stdout(), "{}\n", line).unwrap(); } else { @@ -35,13 +39,13 @@ fn main () { if possible_match == '<' && !is_in_inline_code { is_in_html_tag = true; } - if possible_match == '>' { + if possible_match == '>' && !is_in_inline_code { is_in_html_tag = false; } // replace with right/left apostrophe/quote if possible_match == '\'' && !is_in_inline_code && !is_in_html_tag { - if previous_char.is_alphanumeric() || previous_char == '‘' { + if !previous_char.is_whitespace() || previous_char == '‘' { char_to_push = '’'; } else { @@ -49,7 +53,7 @@ fn main () { } } else if possible_match == '"' && !is_in_inline_code && !is_in_html_tag { - if previous_char.is_alphanumeric() || previous_char == '“' { + if !previous_char.is_whitespace() || previous_char == '“' { char_to_push = '”'; } else {