Search in sources :

Example 1 with Parser

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();
}
Also used : Node(org.commonmark.node.Node) Parser(org.commonmark.parser.Parser)

Example 2 with Parser

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())));
    }
}
Also used : MentionExtension(com.fastaccess.provider.markdown.extension.mention.MentionExtension) InsExtension(org.commonmark.ext.ins.InsExtension) StrikethroughExtension(org.commonmark.ext.gfm.strikethrough.StrikethroughExtension) EmojiExtension(com.fastaccess.provider.markdown.extension.emoji.EmojiExtension) Extension(org.commonmark.Extension) AutolinkExtension(org.commonmark.ext.autolink.AutolinkExtension) YamlFrontMatterExtension(org.commonmark.ext.front.matter.YamlFrontMatterExtension) TablesExtension(org.commonmark.ext.gfm.tables.TablesExtension) Node(org.commonmark.node.Node) Parser(org.commonmark.parser.Parser)

Example 3 with Parser

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)));
    }
}
Also used : Node(org.commonmark.node.Node) Parser(org.commonmark.parser.Parser)

Example 4 with Parser

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("&lt;script src=\"https://gist.github.com/(\\w+)/(\\w+)\\.js\">&lt;/script>", "<script src=\"https://gist.github.com/$1/$2\\.js\"></script>");
    }
    return content;
}
Also used : Extension(org.commonmark.Extension) TablesExtension(org.commonmark.ext.gfm.tables.TablesExtension) Node(org.commonmark.node.Node) HtmlRenderer(org.commonmark.renderer.html.HtmlRenderer) Parser(org.commonmark.parser.Parser)

Example 5 with Parser

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));
}
Also used : Node(org.commonmark.node.Node) HtmlRenderer(org.commonmark.renderer.html.HtmlRenderer) Parser(org.commonmark.parser.Parser)

Aggregations

Parser (org.commonmark.parser.Parser)12 Node (org.commonmark.node.Node)11 HtmlRenderer (org.commonmark.renderer.html.HtmlRenderer)7 IOException (java.io.IOException)2 Extension (org.commonmark.Extension)2 TablesExtension (org.commonmark.ext.gfm.tables.TablesExtension)2 ActivityNotFoundException (android.content.ActivityNotFoundException)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 TypedArray (android.content.res.TypedArray)1 Uri (android.net.Uri)1 NonNull (android.support.annotation.NonNull)1 Snackbar (android.support.design.widget.Snackbar)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 InputMethodManager (android.view.inputmethod.InputMethodManager)1 EditText (android.widget.EditText)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 AlertDialogWrapper (com.afollestad.materialdialogs.AlertDialogWrapper)1