use of org.commonmark.Extension 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.Extension 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;
}
Aggregations