Search in sources :

Example 6 with Node

use of org.commonmark.node.Node in project FastHub by k0shk0sh.

the class MentionDelimiterProcessor method process.

@Override
public void process(Text opener, Text closer, int delimiterCount) {
    Node mention = new Mention();
    Node tmp = opener.getNext();
    while (tmp != null && tmp != closer) {
        Node next = tmp.getNext();
        mention.appendChild(tmp);
        tmp = next;
    }
    opener.insertAfter(mention);
}
Also used : Node(org.commonmark.node.Node) Mention(com.fastaccess.provider.markdown.extension.mention.Mention)

Example 7 with Node

use of org.commonmark.node.Node in project FastHub by k0shk0sh.

the class MentionNodeRenderer method renderChildren.

private void renderChildren(Node parent) {
    Node node = parent.getFirstChild();
    while (node != null) {
        Node next = node.getNext();
        context.render(node);
        node = next;
    }
}
Also used : Node(org.commonmark.node.Node)

Example 8 with Node

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

the class DocServlet method showDoc.

private void showDoc(HttpServletRequest req, HttpServletResponse res, GitilesView view, MarkdownToHtml.Builder fmt, Navbar navbar, MarkdownFile srcFile) throws IOException {
    Map<String, Object> data = new HashMap<>();
    data.putAll(navbar.toSoyData());
    MarkdownConfig cfg = navbar.getConfig();
    Node doc = GitilesMarkdown.parse(cfg, srcFile.consumeContent());
    data.put("pageTitle", pageTitle(doc, srcFile));
    if (view.getType() != GitilesView.Type.ROOTED_DOC) {
        data.put("sourceUrl", GitilesView.show().copyFrom(view).toUrl());
        data.put("logUrl", GitilesView.log().copyFrom(view).toUrl());
        data.put("blameUrl", GitilesView.blame().copyFrom(view).toUrl());
    }
    if (cfg.analyticsId != null) {
        data.put("analyticsId", cfg.analyticsId);
    }
    try (OutputStream out = startRenderCompressedStreamingHtml(req, res, SOY_TEMPLATE, data)) {
        Writer w = newWriter(out, res);
        fmt.setConfig(cfg).setFilePath(srcFile.path).build().renderToHtml(new StreamHtmlBuilder(w), doc);
        w.flush();
    } catch (RuntimeIOException e) {
        Throwables.throwIfInstanceOf(e.getCause(), IOException.class);
        throw e;
    }
}
Also used : StreamHtmlBuilder(com.google.gitiles.doc.html.StreamHtmlBuilder) HashMap(java.util.HashMap) Node(org.commonmark.node.Node) OutputStream(java.io.OutputStream) IOException(java.io.IOException) Writer(java.io.Writer)

Example 9 with Node

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

the class GitilesHtmlExtension method inline.

private static void inline(HtmlInline curr) {
    String html = curr.getLiteral();
    Matcher m = BREAK.matcher(html);
    if (m.matches()) {
        switch(m.group(1).toLowerCase()) {
            case "br":
                curr.insertAfter(new HardLineBreak());
                curr.unlink();
                return;
            case "hr":
                curr.insertAfter(new ThematicBreak());
                curr.unlink();
                return;
        }
    }
    m = ANCHOR_OPEN.matcher(html);
    if (m.matches()) {
        String name = m.group(2);
        Node next = curr.getNext();
        // HtmlInline{<a name="id">}HtmlInline{</a>}
        if (isAnchorClose(next)) {
            next.unlink();
            NamedAnchor anchor = new NamedAnchor();
            anchor.setName(name);
            curr.insertAfter(anchor);
            curr.unlink();
            MarkdownUtil.trimPreviousWhitespace(anchor);
            return;
        }
    }
}
Also used : ThematicBreak(org.commonmark.node.ThematicBreak) Matcher(java.util.regex.Matcher) Node(org.commonmark.node.Node) HardLineBreak(org.commonmark.node.HardLineBreak)

Example 10 with Node

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

the class MarkdownToHtml method visit.

private void visit(BlockNote node) {
    html.open("div").attribute("class", node.getClassName());
    Node f = node.getFirstChild();
    if (f == node.getLastChild() && f instanceof Paragraph) {
        // Avoid <p> inside <div> if there is only one <p>.
        visitChildren(f);
    } else {
        visitChildren(node);
    }
    html.close("div");
}
Also used : Node(org.commonmark.node.Node) CustomNode(org.commonmark.node.CustomNode) Paragraph(org.commonmark.node.Paragraph)

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