【blog】MarkDown语法解析为HTML工具

txtmark

<dependency>
    <groupId>es.nitaur.markdown</groupId>
    <artifactId>txtmark</artifactId>
    <version>0.16</version>
</dependency>
import com.github.rjeschke.txtmark.Processor;

public void setContent(String content) {
    this.content = content;
    this.htmlContent = Processor.process(content);
}

commonmark

<dependency>
    <groupId>com.atlassian.commonmark</groupId>
    <artifactId>commonmark</artifactId>
    <version>0.10.0</version>
</dependency>
import com.github.rjeschke.txtmark.Processor;
import org.commonmark.node.Node;
import org.commonmark.parser.Parser;
import org.commonmark.renderer.html.HtmlRenderer;
import org.springframework.beans.BeanUtils;

Parser parser = Parser.builder().build();
Node document = parser.parse(article.getContent());
HtmlRenderer renderer = HtmlRenderer.builder().build();
String htmlContent = renderer.render(document);
article.setHtmlContent(htmlContent);

或者查看Tale源码封装的工具类!

上一篇:标签跳转传值。


下一篇:Ajax请求跨域问题 -- 转载