use of org.commonmark.parser.Parser in project sql-boot by sql-boot.
the class MarkdownFile method parse.
public Map<String, String> parse() {
Parser parser = Parser.builder().build();
Node document = parser.parse(text);
CustomVisitor visitor = new CustomVisitor();
document.accept(visitor);
return visitor.getMap();
}
use of org.commonmark.parser.Parser in project FastHub by k0shk0sh.
the class MarkDownProvider method render.
protected static void render(@NonNull TextView textView, String markdown, int width) {
List<Extension> extensions = Arrays.asList(StrikethroughExtension.create(), AutolinkExtension.create(), TablesExtension.create(), InsExtension.create(), EmojiExtension.create(), MentionExtension.create(), YamlFrontMatterExtension.create());
Parser parser = Parser.builder().extensions(extensions).build();
try {
Node node = parser.parse(markdown);
String rendered = HtmlRenderer.builder().extensions(extensions).build().render(node);
HtmlHelper.htmlIntoTextView(textView, rendered, (width - (textView.getPaddingStart() + textView.getPaddingEnd())));
} catch (Exception ignored) {
HtmlHelper.htmlIntoTextView(textView, markdown, (width - (textView.getPaddingStart() + textView.getPaddingEnd())));
}
}
use of org.commonmark.parser.Parser in project FastHub by k0shk0sh.
the class MarkDownProvider method stripMdText.
public static void stripMdText(@NonNull TextView textView, String markdown) {
if (!InputHelper.isEmpty(markdown)) {
Parser parser = Parser.builder().build();
Node node = parser.parse(markdown);
textView.setText(stripHtml(HtmlRenderer.builder().build().render(node)));
}
}
use of org.commonmark.parser.Parser in project tale by otale.
the class TaleUtils method mdToHtml.
/**
* markdown转换为html
*
* @param markdown
* @return
*/
public static String mdToHtml(String markdown) {
if (StringKit.isBlank(markdown)) {
return "";
}
List<Extension> extensions = Arrays.asList(TablesExtension.create());
Parser parser = Parser.builder().extensions(extensions).build();
Node document = parser.parse(markdown);
HtmlRenderer renderer = HtmlRenderer.builder().extensions(extensions).build();
String content = renderer.render(document);
content = Commons.emoji(content);
// 支持网易云音乐输出
if (TaleConst.BCONF.getBoolean("app.support_163_music", true) && content.contains("[mp3:")) {
content = content.replaceAll("\\[mp3:(\\d+)\\]", "<iframe frameborder=\"no\" border=\"0\" marginwidth=\"0\" marginheight=\"0\" width=350 height=106 src=\"//music.163.com/outchain/player?type=2&id=$1&auto=0&height=88\"></iframe>");
}
// 支持gist代码输出
if (TaleConst.BCONF.getBoolean("app.support_gist", true) && content.contains("https://gist.github.com/")) {
content = content.replaceAll("<script src=\"https://gist.github.com/(\\w+)/(\\w+)\\.js\"></script>", "<script src=\"https://gist.github.com/$1/$2\\.js\"></script>");
}
return content;
}
use of org.commonmark.parser.Parser in project TOSCAna by StuPro-TOSCAna.
the class ReadmeBuilder method toString.
@Override
public String toString() {
Parser markdownParser = Parser.builder().build();
Node markdownDocument = markdownParser.parse(this.markdownText);
HtmlRenderer renderer = HtmlRenderer.builder().build();
return TEMPLATE.replace(README_TEMPLATE_TITLE_KEY, this.pageTitle).replace(README_TEMPLATE_BODY_KEY, renderer.render(markdownDocument));
}
Aggregations