io.github.sinri.keel.markdown.KeelMarkdownKit Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Keel Show documentation
Show all versions of Keel Show documentation
A website framework with VERT.X for ex-PHP-ers, exactly Ark Framework Users.
The newest version!
package io.github.sinri.keel.markdown;
import org.commonmark.Extension;
import org.commonmark.ext.gfm.tables.TablesExtension;
import org.commonmark.node.Node;
import org.commonmark.parser.Parser;
import org.commonmark.renderer.html.HtmlRenderer;
import java.util.List;
/**
* @see commonmark java readme
* @since 1.12 based on `org.commonmark`
*/
public class KeelMarkdownKit {
private List extensions;
private Parser markdownParser;
private HtmlRenderer htmlRenderer;
public KeelMarkdownKit() {
extensions = List.of(TablesExtension.create());
markdownParser = Parser.builder()
.extensions(extensions)
.build();
htmlRenderer = HtmlRenderer.builder()
.extensions(extensions)
.build();
}
public KeelMarkdownKit(List extensions) {
this.extensions = extensions;
markdownParser = Parser.builder()
.extensions(extensions)
.build();
htmlRenderer = HtmlRenderer.builder()
.extensions(extensions)
.build();
}
public KeelMarkdownKit resetExtensions(List extensions) {
this.extensions = extensions;
markdownParser = Parser.builder()
.extensions(extensions)
.build();
htmlRenderer = HtmlRenderer.builder()
.extensions(extensions)
.build();
return this;
}
public KeelMarkdownKit appendExtensions(Extension extension) {
this.extensions.add(extension);
markdownParser = Parser.builder()
.extensions(extensions)
.build();
htmlRenderer = HtmlRenderer.builder()
.extensions(extensions)
.build();
return this;
}
public List getExtensions() {
return extensions;
}
public Parser getMarkdownParser() {
return markdownParser;
}
public HtmlRenderer getHtmlRenderer() {
return htmlRenderer;
}
public String convertMarkdownToHtml(String md) {
Node document = markdownParser.parse(md);
return htmlRenderer.render(document);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy