The use guide of the Marked framework in the Java library
The Marked framework is a popular JavaScript library for analysis and conversion of Markdown text.Use the MARKED framework in the Java library, which can easily convert the Markdown text into HTML or other format documents.This article will introduce the basic guidelines for the Marked framework and provide some Java code examples.
1. Introduction to dependencies
You need to introduce the dependencies of the MARKED framework in the Java project. You can achieve it by adding the following code to the pom.xml file of the project:
<dependencies>
<dependency>
<groupId>org.commonmark</groupId>
<artifactId>commonmark</artifactId>
<version>0.15.2</version>
</dependency>
</dependencies>
2. Use examples
The use of the MARKED framework in the Java code can be divided into the following steps:
1. Create MarkDownParser object:
import org.commonmark.parser.Parser;
Parser parser = Parser.builder().build();
2. Analyze Markdown text:
import org.commonmark.node.Node;
import org.commonmark.parser.Parser;
Parser parser = Parser.builder().build();
Node document = parser.parse("## Hello, *Marked*!");
3. Create HTMLRENDERER object:
import org.commonmark.renderer.html.HtmlRenderer;
HtmlRenderer renderer = HtmlRenderer.builder().build();
4. Convert the analytical node to HTML format:
import org.commonmark.node.Node;
import org.commonmark.parser.Parser;
import org.commonmark.renderer.html.HtmlRenderer;
Parser parser = Parser.builder().build();
Node document = parser.parse("## Hello, *Marked*!");
HtmlRenderer renderer = HtmlRenderer.builder().build();
String html = renderer.render(document);
System.out.println(html);
The above code will output the following HTML content:
html
<h2>Hello, <em>Marked</em>!</h2>
Third, more functions
In addition to converting Markdown to HTML, the MARKED framework also provides other functions, such as custom plug -in, grammar expansion, etc.According to specific needs, you can study and use these functions to handle Markdown text more flexibly.
Fourth, summary
The Marked framework is a popular Markdown analysis and conversion tool used in the Java library.Through a few simple steps, the Markdown text can be converted into a document in HTML format to achieve customized parsing and rendering effects.It is hoped that this article can help readers understand how to use the Marked framework in the Java project and provide some basic examples.