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
42 stars 37 forks source link

Incorrect serialization of link text #25

Closed ISSOtm closed 3 years ago

ISSOtm commented 3 years ago

tl;dr: [\[1\]](...), after serialization (pulldown_cmark) and deserialization (pulldown_cmark_to_cmark), became [\[1]](...).

The following test program demonstrates the bug:

use pulldown_cmark::{CowStr, Event, LinkType, Tag};
use pulldown_cmark_to_cmark::cmark;

fn main() {
    let events = &[
        Event::Start(Tag::Link(
            LinkType::Inline,
            CowStr::Borrowed("imgs/hello.png"),
            CowStr::Borrowed(""),
        )),
        Event::Text(CowStr::Borrowed("[1")),
        Event::Text(CowStr::Borrowed("]")),
        Event::End(Tag::Link(
            LinkType::Inline,
            CowStr::Borrowed("imgs/hello.png"),
            CowStr::Borrowed(""),
        )),
    ];

    let mut buf = String::new();
    cmark(events.iter(), &mut buf, None).unwrap();
    println!("{}", buf);
}
[dependencies]
pulldown-cmark-to-cmark = "6.0.0"
pulldown-cmark = "0.8.0"

(This Event stream was generated by a pulldown_cmark parser; I have a full trace provided by inspect, if you want. The two Event::Texts are genuine.)

I'm not sure why, but the opening brace gets escaped, but not the closing one; this causes gbdev/pandocs#301.

Byron commented 3 years ago

Thanks for reporting! This must have been an oversight. It now escapes all closing square brackets it sees even if these weren't escaped before, but that shouldn't be a problem.

A patch release was created, too: 6.0.1 .

ISSOtm commented 3 years ago

Thank you! That was fast ^^