Byron / pulldown-cmark-to-cmark

Convert pulldown-cmark Events back to the string they were parsed from
https://docs.rs/crate/pulldown-cmark-to-cmark
Apache License 2.0
43 stars 37 forks source link

`cmark_with_source_range_and_options` escapes special characters within code blocks when no range is available #73

Closed max-heller closed 3 months ago

max-heller commented 3 months ago

In the following test, a # in a code block is escaped by cmark_with_source_range_and_options when no range is provided even though the contents of code blocks should be treated as verbatim.

#[test]
fn bug() {
    let input = r#"
```rust
# fn main() {
println!("Hello, world!");
# }

"#; let iter = pulldown_cmark::Parser::new(input); let mut output = String::new(); pulldown_cmark_to_cmark::cmark_with_source_range_and_options( iter.map(|e| (e, None)), input, &mut output, Default::default(), ) .unwrap(); assert_eq!(input, output); }


```console
---- tests::bug stdout ----
thread 'tests::bug' panicked at src/lib.rs:1186:9:
assertion `left == right` failed
  left: "\n```rust\n# fn main() {\n    println!(\"Hello, world!\");\n# }\n```\n"
 right: "\n````rust\n\\# fn main() {\n    println!(\"Hello, world!\");\n# }\n````"

Note the \\#

Byron commented 3 months ago

Thanks a lot for reporting! It's good that the new release is incrementing the minor version to indicate a breaking release, so fewest users should get surprised by this. If there is demand, v0.14 could also be yanked though until there is a fix.

This is probably related to #71, so just in case I CC @SichangHe.

SichangHe commented 3 months ago

I think I know what I messed up. Please wait a bit for a fix PR.

Byron commented 3 months ago

A new release is now available here: https://github.com/Byron/pulldown-cmark-to-cmark/releases/tag/v14.0.1