Search in sources :

Example 1 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, MarkdownConfig cfg, MarkdownToHtml.Builder fmt, MarkdownFile navFile, MarkdownFile srcFile) throws IOException {
    Map<String, Object> data = new HashMap<>();
    Navbar navbar = new Navbar();
    if (navFile != null) {
        navbar.setFormatter(fmt.setFilePath(navFile.path).build());
        navbar.setMarkdown(navFile.content);
    }
    data.putAll(navbar.toSoyData());
    Node doc = GitilesMarkdown.parse(srcFile.content);
    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);
    }
    data.put("bodyHtml", fmt.setFilePath(srcFile.path).build().toSoyHtml(doc));
    String page = renderer.render(SOY_TEMPLATE, data);
    byte[] raw = page.getBytes(UTF_8);
    res.setContentType(FormatType.HTML.getMimeType());
    res.setCharacterEncoding(UTF_8.name());
    setCacheHeaders(req, res);
    if (acceptsGzipEncoding(req)) {
        res.addHeader(HttpHeaders.VARY, HttpHeaders.ACCEPT_ENCODING);
        res.setHeader(HttpHeaders.CONTENT_ENCODING, "gzip");
        raw = gzip(raw);
    }
    res.setContentLength(raw.length);
    res.setStatus(HttpServletResponse.SC_OK);
    res.getOutputStream().write(raw);
}
Also used : HashMap(java.util.HashMap) Node(org.commonmark.node.Node)

Example 2 with Node

use of org.commonmark.node.Node 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 3 with Node

use of org.commonmark.node.Node 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 4 with Node

use of org.commonmark.node.Node 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 5 with Node

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

the class EmojiDelimiterProcessor method process.

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

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