diff --git a/src/regexes.rs b/src/regexes.rs index 5621f8b..b73350b 100644 --- a/src/regexes.rs +++ b/src/regexes.rs @@ -7,8 +7,7 @@ lazy_static! { pub static ref RE_NEWLINES: Regex = Regex::new(r"\n\n\n+").unwrap(); pub static ref RE_TABS: Regex = Regex::new(r"\t").unwrap(); pub static ref RE_TRAIL: Regex = Regex::new(r" +\n").unwrap(); - pub static ref RE_PERCENT: Regex = Regex::new(r"\\\%").unwrap(); - pub static ref RE_COMMENT: Regex = Regex::new(r"\%.*").unwrap(); + pub static ref RE_COMMENT: Regex = Regex::new(r"(?P.*^|[^\\])(?P\%.*$)").unwrap(); pub static ref RE_ITEM: Regex = Regex::new(r".*\\item.*").unwrap(); pub static ref RE_DOCUMENT_BEGIN: Regex = Regex::new(r".*\\begin\{document\}.*").unwrap(); diff --git a/src/subs.rs b/src/subs.rs index a847460..dd2d8d4 100644 --- a/src/subs.rs +++ b/src/subs.rs @@ -42,6 +42,5 @@ pub fn remove_trailing_spaces(file: &str) -> String { //} pub fn remove_comment(line: &str) -> String { - let new_line = RE_PERCENT.replace_all(line, "").to_string(); - RE_COMMENT.replace_all(&new_line, "").to_string() + RE_COMMENT.replace_all(line, "$text").to_string() } diff --git a/tests/comments_in.tex b/tests/comments_in.tex index 0fba314..c6ffac9 100644 --- a/tests/comments_in.tex +++ b/tests/comments_in.tex @@ -15,4 +15,8 @@ % Similarly they might contain \begin{align} % unmatched environment tags. +This is a percent sign \% and not a comment + +Some lines might have both \% percents % and comments \end{align} + \end{document} diff --git a/tests/comments_out.tex b/tests/comments_out.tex index 853727a..bc25171 100644 --- a/tests/comments_out.tex +++ b/tests/comments_out.tex @@ -15,4 +15,8 @@ % Similarly they might contain \begin{align} % unmatched environment tags. +This is a percent sign \% and not a comment + +Some lines might have both \% percents % and comments \end{align} + \end{document}