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
源码封装的工具类!