A Java library to transform documentation files (like Markdown) into HTML with optional features such as syntax highlighting, Mermaid diagrams, GitHub emojis, and Font Awesome icons. In addition, it can extract the document title and generate a table of contents.
This library is intended to be used in conjunction with j2html for building HTML documents in Java.
- Java 21 or higher
Add the following dependency to your pom.xml:
<dependency>
<groupId>org.myjtools</groupId>
<artifactId>doc2html</artifactId>
<version>1.0.0</version>
</dependency>import org.myjtools.doc2html.*;
import java.io.FileReader;
// Create a Markdown generator
HtmlGenerator generator = new MarkdownHtmlGenerator();
// Enable optional features
generator.setFeature(Feature.SYNTAX_HIGHLIGHTING, true);
generator.setFeature(Feature.MERMAID_DIAGRAMS, true);
generator.setFeature(Feature.GITHUB_EMOJIS, true);
// Transform a Markdown file to HtmlDoc
try (FileReader reader = new FileReader("README.md")) {
HtmlDoc doc = generator.transform(reader);
// Get the generated components
HeadTag head = doc.head(); // Contains CSS/JS resources
MainTag main = doc.main(); // Contains the HTML content
NavTag toc = doc.tableOfContents(1, 3); // Table of contents (h1-h3)
String title = doc.titleText(); // Extracted title
}| Feature | Description |
|---|---|
SYNTAX_HIGHLIGHTING |
Code block syntax highlighting using Prism.js |
MERMAID_DIAGRAMS |
Render Mermaid diagrams |
GITHUB_EMOJIS |
Convert GitHub emoji codes (e.g., :smile:) to Unicode |
FONT_AWESOME_ICONS |
Include Font Awesome CSS |
MIT License