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

use FlexmarkHtmlConverter ,html to markdown,# no escape #616

Open wanli-x opened 2 days ago

wanli-x commented 2 days ago

The last two lines of output are the same, ### should become \###

    public static String htmlToMarkdown(String html) {
        FlexmarkHtmlConverter converter = FlexmarkHtmlConverter.builder().build();
        return converter.convert(html);
    }
    public static void main(String[] args) {
        System.out.println(htmlToMarkdown("<h1>Add: live templates starting with </h1>" +
                "<h2>Add: live templates starting with </h2>" +
                "<h3>Add: live templates starting with </h3>" +
                "<p>### Add: live templates starting with</p>"));
    }
wanli-x commented 2 days ago

I saw this piece of code

public @NotNull String escapeSpecialChars(@NotNull String text) {
            if (!myHtmlConverterOptions.skipCharEscape) {
                text = text.replace("\\", "\\\\");
                text = text.replace("*", "\\*");
                text = text.replace("~", "\\~");
                text = text.replace("^", "\\^");
                text = text.replace("&", "\\&");
                text = text.replace("<", "\\<").replace(">", "\\>");
                text = text.replace("[", "\\[").replace("]", "\\]");
                text = text.replace("|", "\\|").replace("`", "\\`");
                text = text.replace("\u00A0", myHtmlConverterOptions.nbspText);
            }
       return text;
 }