Search in sources :

Example 16 with Node

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

the class GoCommentReformatter method reformat.

@Override
public String reformat(String comment) {
    Node root = PARSER.parse(comment);
    GoVisitor visitor = new GoVisitor();
    try {
        root.accept(visitor);
        return visitor.toString();
    } catch (ErrorMarkdownVisitor.UnimplementedRenderException e) {
        LOGGER.log(Level.WARNING, "markdown contains elements we don't handle; copying doc verbatim", e);
        return comment;
    }
}
Also used : Node(org.commonmark.node.Node) ErrorMarkdownVisitor(com.google.api.codegen.util.ErrorMarkdownVisitor)

Example 17 with Node

use of org.commonmark.node.Node in project hippo by NHS-digital-website.

the class CommonmarkMarkdownConverter method renderMarkdownText.

private String renderMarkdownText(final String markdown, final String headingIdPrefix, int topHeadingLevel) {
    final List<Extension> extensions = singletonList(TablesExtension.create());
    final Node document = parse(markdown, extensions);
    normalizeHeadingsLevels(document, topHeadingLevel);
    addBreaksBeforeH2Headings(document);
    return renderMarkdownModel(document, extensions, headingIdPrefix);
}
Also used : Extension(org.commonmark.Extension) TablesExtension(org.commonmark.ext.gfm.tables.TablesExtension) Node(org.commonmark.node.Node)

Example 18 with Node

use of org.commonmark.node.Node in project hippo by NHS-digital-website.

the class ThematicBreakAttributeProviderTest method ignoresElementOtherThanThematicBreak.

@Test
public void ignoresElementOtherThanThematicBreak() {
    // given
    final Node nodeOtherThanThematicBreak = new TableBlock();
    // when
    thematicBreakAttributeProvider.setAttributes(nodeOtherThanThematicBreak, "tagName is ignored", attributes);
    // then
    then(attributes).shouldHaveZeroInteractions();
}
Also used : TableBlock(org.commonmark.ext.gfm.tables.TableBlock) Node(org.commonmark.node.Node) Test(org.junit.Test)

Example 19 with Node

use of org.commonmark.node.Node in project hippo by NHS-digital-website.

the class CodeAttributeProviderTest method setsCodeInlineCssClassOnCodeElement.

@Test
public void setsCodeInlineCssClassOnCodeElement() {
    // given
    final Node nodeCode = new Code();
    // when
    codeAttributeProvider.setAttributes(nodeCode, "tagName is ignored", attributes);
    // then
    then(attributes).should().put("class", "nhsd-a-text-highlight nhsd-a-text-highlight--code");
    then(attributes).shouldHaveNoMoreInteractions();
}
Also used : Node(org.commonmark.node.Node) Code(org.commonmark.node.Code) Test(org.junit.Test)

Example 20 with Node

use of org.commonmark.node.Node in project hippo by NHS-digital-website.

the class ListAttributeProviderTest method setsCssClassOnOrderedListElement.

@Test
public void setsCssClassOnOrderedListElement() {
    // given
    final Node nodeOrderedList = new OrderedList();
    // when
    listAttributeProvider.setAttributes(nodeOrderedList, "tagName is ignored", attributes);
    // then
    then(attributes).should().put("class", "nhsd-t-list nhsd-t-list--number");
    then(attributes).shouldHaveNoMoreInteractions();
}
Also used : OrderedList(org.commonmark.node.OrderedList) Node(org.commonmark.node.Node) Test(org.junit.Test)

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