引入jar包依赖
<dependency>
<groupId>com.vladsch.flexmark</groupId>
<artifactId>flexmark-all</artifactId>
<version>0.50.42</version>
</dependency>
写一个类,给这个类传一个md语法的文字,它会返回一个 html语法的文章
package cn.huiani.util;
import com.vladsch.flexmark.html.HtmlRenderer;
import com.vladsch.flexmark.parser.Parser;
import com.vladsch.flexmark.util.ast.Node;
import com.vladsch.flexmark.util.data.MutableDataSet;
/**
* Created by Administrator on 2019/11/15 0015.
*/
public class MdToHtml {
public static String convert(String md) {
MutableDataSet options = new MutableDataSet();
Parser parser = Parser.builder(options).build();
HtmlRenderer renderer = HtmlRenderer.builder(options).build();
// You can re-use parser and renderer instances
Node document = parser.parse(md);
String html = renderer.render(document); // "<p>This is <em>Sparta</em></p>\n"
return html;
}
}