Byron/pulldown-cmark-to-cmark

`\\` is translated inconsitently

Aberta

#63 aberto em 24 de nov. de 2023

 (2 comentários) (0 reação) (0 responsável)Rust (46 forks)auto 404
help wanted

Métricas do repositório

Stars
 (60 estrelas)
Métricas de merge de PR
 (Mesclagem média 35m) (1 fundiu PR em 30d)

Description

I have try to prase markdown with the pulldown-cmark crate and to convert it back, using this crate. But \\ is translated back inconsistent. At some point \\ is converted to \ and at other points it is still \\. For Example This line occurs in my markdown files multiple times \\( \int x dx = \frac{x^2}{2} + C \\). The first time it stay the same, all other time it result in \( \int x dx = \frac{x^2}{2} + C \), so the mathjax expression are not render by the mdbook. image

code:

        let markdown_copy = markdown.clone();
        eprintln!("{markdown_copy}");
        let parser = pulldown_cmark::Parser::new(&markdown_copy);
        let mut in_code_block = false;
        let iter = parser.into_iter().map(|f| {
            eprintln!("in  {f:?}");
            let f =match f {
                Event::Text(text) => Event::Text(CowStr::from(text.replace("=>", "⇒"))),
                Event::Start(Tag::CodeBlock(value)) => {in_code_block = true; Event::Start(Tag::CodeBlock(value))},
                Event::End(Tag::CodeBlock(value)) => {in_code_block = false; Event::Start(Tag::CodeBlock(value))}
                f => f 
            };
            eprintln!("out {f:?}");
            f
        });
        let mut output = String::new();
        pulldown_cmark_to_cmark::cmark(iter, &mut output).unwrap();
        eprintln!("{output}");

output: input.md

in  Start(Heading(H1, None, []))
out Start(Heading(H1, None, []))
in  Text(Borrowed("Chapter 1"))
out Text(Boxed("Chapter 1"))
in  End(Heading(H1, None, []))
out End(Heading(H1, None, []))
in  Start(Paragraph)
out Start(Paragraph)
in  Text(Borrowed("hello world."))
out Text(Boxed("hello world."))
in  SoftBreak
out SoftBreak
in  Text(Borrowed("This is a "))
out Text(Boxed("This is a "))
in  Start(Link(Inline, Borrowed("https://duckduckgo.com"), Borrowed("")))
out Start(Link(Inline, Borrowed("https://duckduckgo.com"), Borrowed("")))
in  Text(Borrowed("duck"))
out Text(Boxed("duck"))
in  End(Link(Inline, Borrowed("https://duckduckgo.com"), Borrowed("")))
out End(Link(Inline, Borrowed("https://duckduckgo.com"), Borrowed("")))
in  SoftBreak
out SoftBreak
in  Text(Borrowed("arrows: -> = >"))
out Text(Boxed("arrows: -> = >"))
in  SoftBreak
out SoftBreak
in  Text(Borrowed("ee"))
out Text(Boxed("ee"))
in  End(Paragraph)
out End(Paragraph)
in  Start(Paragraph)
out Start(Paragraph)
in  Text(Borrowed("\\( \\int x dx = \\frac{x^2}{2} + C "))
out Text(Boxed("\\( \\int x dx = \\frac{x^2}{2} + C "))
in  Text(Borrowed("\\)"))
out Text(Boxed("\\)"))
in  End(Paragraph)
out End(Paragraph)
in  Start(CodeBlock(Fenced(Borrowed(""))))
out Start(CodeBlock(Fenced(Borrowed(""))))
in  Text(Borrowed("this arrows should not be replaced:\n-> =>\n"))
out Text(Boxed("this arrows should not be replaced:\n-> ⇒\n"))
in  End(CodeBlock(Fenced(Borrowed(""))))
out Start(CodeBlock(Fenced(Borrowed(""))))
in  Start(Paragraph)
out Start(Paragraph)
in  Text(Borrowed("\\( \\int x dx = \\frac{x^2}{2} + C "))
out Text(Boxed("\\( \\int x dx = \\frac{x^2}{2} + C "))
in  Text(Borrowed("\\)"))
out Text(Boxed("\\)"))
in  End(Paragraph)
out End(Paragraph)
in  Start(Paragraph)
out Start(Paragraph)
in  Text(Borrowed("this should also not be replaced "))
out Text(Boxed("this should also not be replaced "))
in  Code(Borrowed("->"))
out Code(Borrowed("->"))
in  Text(Borrowed(" "))
out Text(Boxed(" "))
in  Code(Borrowed("=>"))
out Code(Borrowed("=>"))
in  Text(Borrowed(". "))
out Text(Boxed(". "))
in  End(Paragraph)
out End(Paragraph)
in  Start(Paragraph)
out Start(Paragraph)
in  Text(Borrowed("\\"))
out Text(Boxed("\\"))
in  Text(Borrowed("["))
out Text(Boxed("["))
in  Text(Borrowed(" \\mu = \\frac{1}{N} \\sum"))
out Text(Boxed(" \\mu = \\frac{1}{N} \\sum"))
in  Text(Borrowed("_"))
out Text(Boxed("_"))
in  Text(Borrowed("{i=0} x_i \\Rightarrow"))
out Text(Boxed("{i=0} x_i \\Rightarrow"))
in  Text(Borrowed("\\"))
out Text(Boxed("\\"))
in  Text(Borrowed("]"))
out Text(Boxed("]"))
in  End(Paragraph)
out End(Paragraph)

output.md

I war forced to upload the markdowns as file, because otherwise github has try to interpret it.

Guia do colaborador