vsch / flexmark-java

CommonMark/Markdown Java parser with source level AST. CommonMark 0.28, emulation of: pegdown, kramdown, markdown.pl, MultiMarkdown. With HTML to MD, MD to PDF, MD to DOCX conversion modules.
BSD 2-Clause "Simplified" License
2.21k stars 260 forks source link

Flexmark interferes with KaTeX code #593

Open mtrevisan opened 9 months ago

mtrevisan commented 9 months ago

It seems that flexmark processes text inside KaTeX code, and I have to pre-process the text to add backslashes and removes
in order to render KaTeX correctly. What am I doing wrong?

The code I'm using is as simple as

private static Parser PARSER;
private static HtmlRenderer RENDERER;
static{
    MutableDataSet options = new MutableDataSet()
        .set(HtmlRenderer.SOFT_BREAK, "<br />\n");

    PARSER = Parser.builder(options)
        .build();
    RENDERER = HtmlRenderer.builder(options)
        .build();
}

and

Node document = PARSER.parse(content);
String html = RENDERER.render(document);

Please provide as much information about where the bug is located or what you were using:

To reproduce the problem:

public static void main(String[] args){
    String input = """
$$
alpha[\%]
$$
        """;
    System.out.println(RENDERER.render(PARSER.parse(input)));
}

output:

<p>$$<br />
alpha[%]<br />
$$</p>

output expected:

<p>$$
alpha[\%]
$$</p>