Switch to getting the contents with a function to handle the escaped lines.

This commit is contained in:
Tom Alexander 2023-10-04 12:59:57 -04:00
parent b56d847cfa
commit afb43ff34f
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 35 additions and 2 deletions

View File

@ -0,0 +1,10 @@
#+begin_example
,* foo
,** bar
,*** baz
lorem
, ipsum
,#+begin_src dolar
,#+end_src
#+end_example

View File

@ -1549,11 +1549,12 @@ fn compare_example_block<'b, 's>(
// Compare value
let contents = get_property_quoted_string(emacs, ":value")?.unwrap_or(String::new());
if contents != rust.contents {
let rust_contents = rust.get_contents();
if contents != rust_contents {
this_status = DiffStatus::Bad;
message = Some(format!(
"Value mismatch (emacs != rust) {:?} != {:?}",
contents, rust.contents
contents, rust_contents
));
}

View File

@ -237,3 +237,25 @@ impl<'s> Comment<'s> {
ret
}
}
impl<'s> ExampleBlock<'s> {
/// Get the inner contents of the ExampleBlock with the escaping commas removed.
pub fn get_contents(&self) -> String {
let mut ret = String::with_capacity(self.contents.len());
for line in self.contents.lines() {
let first_comma = line.find(",#+").or_else(|| line.find(",*"));
if let Some(first_comma) = first_comma {
let before_first_comma = &line[..first_comma];
let is_escaping_comma = before_first_comma.chars().all(char::is_whitespace);
if is_escaping_comma {
ret.push_str(&line[(first_comma + 1)..]);
} else {
ret.push_str(line);
}
} else {
ret.push_str(line);
}
}
ret
}
}