Search in sources :

Example 26 with Node

use of org.commonmark.node.Node in project gitiles by GerritCodeReview.

the class SmartQuotedExtension method quote.

private static void quote(Type type, Text opener, Text closer) {
    SmartQuoted quote = new SmartQuoted();
    quote.setType(type);
    for (Node t = opener.getNext(); t != null && t != closer; ) {
        Node next = t.getNext();
        quote.appendChild(t);
        t = next;
    }
    opener.insertAfter(quote);
}
Also used : Node(org.commonmark.node.Node)

Example 27 with Node

use of org.commonmark.node.Node in project mdw-designer by CenturyLinkCloud.

the class MarkdownRenderer method renderHtml.

public String renderHtml() {
    if (markdown == null || markdown.trim().isEmpty())
        return "";
    else {
        Parser parser = Parser.builder().build();
        Node document = parser.parse(markdown);
        HtmlRenderer renderer = HtmlRenderer.builder().build();
        return "<div style=\"height:100%;overflow:auto;font-family:'Helvetica Neue', Helvetica, Arial, sans-serif\">" + renderer.render(document) + "</div>";
    }
}
Also used : Node(org.commonmark.node.Node) HtmlRenderer(org.commonmark.renderer.html.HtmlRenderer) Parser(org.commonmark.parser.Parser)

Example 28 with Node

use of org.commonmark.node.Node in project MagiskManager by topjohnwu.

the class MarkDownWindow method doInBackground.

@Override
protected String doInBackground(Void... voids) {
    MagiskManager mm = MagiskManager.get();
    String md;
    if (mUrl != null) {
        md = WebService.getString(mUrl);
    } else {
        try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
            ShellUtils.pump(is, out);
            md = out.toString();
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }
    String css;
    try (InputStream in = mm.getResources().openRawResource(mm.isDarkTheme ? R.raw.dark : R.raw.light);
        ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        ShellUtils.pump(in, out);
        css = out.toString();
        in.close();
    } catch (IOException e) {
        e.printStackTrace();
        return "";
    }
    Parser parser = Parser.builder().build();
    HtmlRenderer renderer = HtmlRenderer.builder().build();
    Node doc = parser.parse(md);
    return String.format("<style>%s</style>%s", css, renderer.render(doc));
}
Also used : MagiskManager(com.topjohnwu.magisk.MagiskManager) InputStream(java.io.InputStream) Node(org.commonmark.node.Node) HtmlRenderer(org.commonmark.renderer.html.HtmlRenderer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Parser(org.commonmark.parser.Parser)

Example 29 with Node

use of org.commonmark.node.Node in project tale by otale.

the class TaleUtils method mdToHtml.

/**
 * markdown转换为html
 */
public static String mdToHtml(String markdown) {
    if (StringKit.isBlank(markdown)) {
        return "";
    }
    List<Extension> extensions = Collections.singletonList(TablesExtension.create());
    Parser parser = Parser.builder().extensions(extensions).build();
    Node document = parser.parse(markdown);
    HtmlRenderer renderer = HtmlRenderer.builder().attributeProviderFactory(context -> new LinkAttributeProvider()).extensions(extensions).build();
    String content = renderer.render(document);
    content = Commons.emoji(content);
    // 支持网易云音乐输出
    if (TaleConst.BCONF.getBoolean(ENV_SUPPORT_163_MUSIC, true) && content.contains(MP3_PREFIX)) {
        content = content.replaceAll(MUSIC_REG_PATTERN, MUSIC_IFRAME);
    }
    // 支持gist代码输出
    if (TaleConst.BCONF.getBoolean(ENV_SUPPORT_GIST, true) && content.contains(GIST_PREFIX_URL)) {
        content = content.replaceAll(GIST_REG_PATTERN, GIST_REPLATE_PATTERN);
    }
    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 30 with Node

use of org.commonmark.node.Node in project toolkit by googleapis.

the class ErrorMarkdownVisitor method visitChildren.

protected void visitChildren(Node node) {
    Node child = node.getFirstChild();
    while (child != null) {
        Node next = child.getNext();
        child.accept(this);
        child = next;
    }
}
Also used : CustomNode(org.commonmark.node.CustomNode) Node(org.commonmark.node.Node)

Aggregations

Node (org.commonmark.node.Node)42 Parser (org.commonmark.parser.Parser)18 HtmlRenderer (org.commonmark.renderer.html.HtmlRenderer)12 Test (org.junit.Test)9 Extension (org.commonmark.Extension)7 TablesExtension (org.commonmark.ext.gfm.tables.TablesExtension)7 IOException (java.io.IOException)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 DateFormat (java.text.DateFormat)2 HashMap (java.util.HashMap)2 TableBlock (org.commonmark.ext.gfm.tables.TableBlock)2 Code (org.commonmark.node.Code)2 CustomNode (org.commonmark.node.CustomNode)2 AppWidgetManager (android.appwidget.AppWidgetManager)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 ComponentName (android.content.ComponentName)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1