当前位置: 首页>>代码示例>>Java>>正文


Java Node类代码示例

本文整理汇总了Java中org.commonmark.node.Node的典型用法代码示例。如果您正苦于以下问题:Java Node类的具体用法?Java Node怎么用?Java Node使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Node类属于org.commonmark.node包,在下文中一共展示了Node类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: render

import org.commonmark.node.Node; //导入依赖的package包/类
public String render(String text, String format) {
    if (text == null || text.length() == 0) {
        return text;
    }

    try {
        Parser parser = Parser.builder().build();
        Node document = parser.parse(text);

        Renderer renderer;
        if (format.equals("html")) {
            renderer = HtmlRenderer.builder().build();
        } else {
            renderer = TextContentRenderer.builder().build();
        }

        return renderer.render(document);
    } catch (Exception e) {
        logger.error("A problem occurred while rendering an email: {}", e);

        return text;
    }
}
 
开发者ID:BjoernKW,项目名称:MailTrigger,代码行数:24,代码来源:MailRenderer.java

示例2: render

import org.commonmark.node.Node; //导入依赖的package包/类
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())));
    }
}
 
开发者ID:duyp,项目名称:mvvm-template,代码行数:25,代码来源:MarkDownProvider.java

示例3: generateContents

import org.commonmark.node.Node; //导入依赖的package包/类
public String generateContents(Page page) throws IOException {
    List<Extension> extensions = Collections.singletonList(TablesExtension.create());

    Parser parser = Parser
            .builder()
            .extensions(extensions)
            .build();

    HtmlRenderer renderer = HtmlRenderer
            .builder()
            .attributeProvider((node, attributes) -> {
                if (node instanceof TableBlock) {
                    attributes.put("class", "table");
                }
            })
            .extensions(extensions)
            .build();

    Node document = parser.parseReader(new FileReader(page.getFile()));

    return renderer.render(document);
}
 
开发者ID:UniversalMinecraftAPI,项目名称:UniversalMinecraftAPI,代码行数:23,代码来源:PageGenerator.java

示例4: MockBodyPost

import org.commonmark.node.Node; //导入依赖的package包/类
public MockBodyPost(String bodyMarkdown) {

        super("","",null,null,
                1, 1, "", bodyMarkdown, null, null, null, "", "");
        SOUser asker = new SOUser("testUser",-1,1,"registered");
        SOUser answerer = new SOUser("testUser",-1,1,"unregistered");

        setAnswerCreationDate(Instant.now());
        setQuestionCreationDate(Instant.EPOCH);
        setAsker(asker);
        setAnswerer(answerer);

        Parser parser = Parser.builder().build();
        Node document = parser.parse(bodyMarkdown);
        HtmlRenderer renderer = HtmlRenderer.builder().build();
        setBody(renderer.render(document));

    }
 
开发者ID:SOBotics,项目名称:Natty,代码行数:19,代码来源:MockBodyPost.java

示例5: simpleValue

import org.commonmark.node.Node; //导入依赖的package包/类
@Test
public void simpleValue() {
    final String input = "---" +
            "\nhello: world" +
            "\n..." +
            "\n" +
            "\ngreat";
    final String rendered = "<p>great</p>\n";

    YamlFrontMatterVisitor visitor = new YamlFrontMatterVisitor();
    Node document = PARSER.parse(input);
    document.accept(visitor);

    Map<String, List<String>> data = visitor.getData();

    assertEquals(1, data.size());
    assertEquals("hello", data.keySet().iterator().next());
    assertEquals(1, data.get("hello").size());
    assertEquals("world", data.get("hello").get(0));

    assertRendering(input, rendered);
}
 
开发者ID:atlassian,项目名称:commonmark-java,代码行数:23,代码来源:YamlFrontMatterTest.java

示例6: emptyValue

import org.commonmark.node.Node; //导入依赖的package包/类
@Test
public void emptyValue() {
    final String input = "---" +
            "\nkey:" +
            "\n---" +
            "\n" +
            "\ngreat";
    final String rendered = "<p>great</p>\n";

    YamlFrontMatterVisitor visitor = new YamlFrontMatterVisitor();
    Node document = PARSER.parse(input);
    document.accept(visitor);

    Map<String, List<String>> data = visitor.getData();

    assertEquals(1, data.size());
    assertEquals("key", data.keySet().iterator().next());
    assertEquals(0, data.get("key").size());

    assertRendering(input, rendered);
}
 
开发者ID:atlassian,项目名称:commonmark-java,代码行数:22,代码来源:YamlFrontMatterTest.java

示例7: listValues

import org.commonmark.node.Node; //导入依赖的package包/类
@Test
public void listValues() {
    final String input = "---" +
            "\nlist:" +
            "\n  - value1" +
            "\n  - value2" +
            "\n..." +
            "\n" +
            "\ngreat";
    final String rendered = "<p>great</p>\n";

    YamlFrontMatterVisitor visitor = new YamlFrontMatterVisitor();
    Node document = PARSER.parse(input);
    document.accept(visitor);

    Map<String, List<String>> data = visitor.getData();

    assertEquals(1, data.size());
    assertTrue(data.containsKey("list"));
    assertEquals(2, data.get("list").size());
    assertEquals("value1", data.get("list").get(0));
    assertEquals("value2", data.get("list").get(1));

    assertRendering(input, rendered);
}
 
开发者ID:atlassian,项目名称:commonmark-java,代码行数:26,代码来源:YamlFrontMatterTest.java

示例8: literalValue1

import org.commonmark.node.Node; //导入依赖的package包/类
@Test
public void literalValue1() {
    final String input = "---" +
            "\nliteral: |" +
            "\n  hello markdown!" +
            "\n  literal thing..." +
            "\n---" +
            "\n" +
            "\ngreat";
    final String rendered = "<p>great</p>\n";

    YamlFrontMatterVisitor visitor = new YamlFrontMatterVisitor();
    Node document = PARSER.parse(input);
    document.accept(visitor);

    Map<String, List<String>> data = visitor.getData();

    assertEquals(1, data.size());
    assertTrue(data.containsKey("literal"));
    assertEquals(1, data.get("literal").size());
    assertEquals("hello markdown!\nliteral thing...", data.get("literal").get(0));

    assertRendering(input, rendered);
}
 
开发者ID:atlassian,项目名称:commonmark-java,代码行数:25,代码来源:YamlFrontMatterTest.java

示例9: literalValue2

import org.commonmark.node.Node; //导入依赖的package包/类
@Test
public void literalValue2() {
    final String input = "---" +
            "\nliteral: |" +
            "\n  - hello markdown!" +
            "\n---" +
            "\n" +
            "\ngreat";
    final String rendered = "<p>great</p>\n";

    YamlFrontMatterVisitor visitor = new YamlFrontMatterVisitor();
    Node document = PARSER.parse(input);
    document.accept(visitor);

    Map<String, List<String>> data = visitor.getData();

    assertEquals(1, data.size());
    assertTrue(data.containsKey("literal"));
    assertEquals(1, data.get("literal").size());
    assertEquals("- hello markdown!", data.get("literal").get(0));

    assertRendering(input, rendered);
}
 
开发者ID:atlassian,项目名称:commonmark-java,代码行数:24,代码来源:YamlFrontMatterTest.java

示例10: empty

import org.commonmark.node.Node; //导入依赖的package包/类
@Test
public void empty() {
    final String input = "---\n" +
            "---\n" +
            "test";
    final String rendered = "<p>test</p>\n";

    YamlFrontMatterVisitor visitor = new YamlFrontMatterVisitor();
    Node document = PARSER.parse(input);
    document.accept(visitor);

    Map<String, List<String>> data = visitor.getData();

    assertTrue(data.isEmpty());

    assertRendering(input, rendered);
}
 
开发者ID:atlassian,项目名称:commonmark-java,代码行数:18,代码来源:YamlFrontMatterTest.java

示例11: yamlInParagraph

import org.commonmark.node.Node; //导入依赖的package包/类
@Test
public void yamlInParagraph() {
    final String input = "# hello\n" +
            "\nhello markdown world!" +
            "\n---" +
            "\nhello: world" +
            "\n---";
    final String rendered = "<h1>hello</h1>\n<h2>hello markdown world!</h2>\n<h2>hello: world</h2>\n";

    YamlFrontMatterVisitor visitor = new YamlFrontMatterVisitor();
    Node document = PARSER.parse(input);
    document.accept(visitor);

    Map<String, List<String>> data = visitor.getData();

    assertTrue(data.isEmpty());

    assertRendering(input, rendered);
}
 
开发者ID:atlassian,项目名称:commonmark-java,代码行数:20,代码来源:YamlFrontMatterTest.java

示例12: yamlOnSecondLine

import org.commonmark.node.Node; //导入依赖的package包/类
@Test
public void yamlOnSecondLine() {
    final String input = "hello\n" +
            "\n---" +
            "\nhello: world" +
            "\n---";
    final String rendered = "<p>hello</p>\n<hr />\n<h2>hello: world</h2>\n";

    YamlFrontMatterVisitor visitor = new YamlFrontMatterVisitor();
    Node document = PARSER.parse(input);
    document.accept(visitor);

    Map<String, List<String>> data = visitor.getData();

    assertTrue(data.isEmpty());

    assertRendering(input, rendered);
}
 
开发者ID:atlassian,项目名称:commonmark-java,代码行数:19,代码来源:YamlFrontMatterTest.java

示例13: nonMatchedStartTag

import org.commonmark.node.Node; //导入依赖的package包/类
@Test
public void nonMatchedStartTag() {
    final String input = "----\n" +
            "test";
    final String rendered = "<hr />\n<p>test</p>\n";

    YamlFrontMatterVisitor visitor = new YamlFrontMatterVisitor();
    Node document = PARSER.parse(input);
    document.accept(visitor);

    Map<String, List<String>> data = visitor.getData();

    assertTrue(data.isEmpty());

    assertRendering(input, rendered);
}
 
开发者ID:atlassian,项目名称:commonmark-java,代码行数:17,代码来源:YamlFrontMatterTest.java

示例14: inList

import org.commonmark.node.Node; //导入依赖的package包/类
@Test
public void inList() {
    final String input = "* ---\n" +
            "  ---\n" +
            "test";
    final String rendered = "<ul>\n<li>\n<hr />\n<hr />\n</li>\n</ul>\n<p>test</p>\n";

    YamlFrontMatterVisitor visitor = new YamlFrontMatterVisitor();
    Node document = PARSER.parse(input);
    document.accept(visitor);

    Map<String, List<String>> data = visitor.getData();

    assertTrue(data.isEmpty());

    assertRendering(input, rendered);
}
 
开发者ID:atlassian,项目名称:commonmark-java,代码行数:18,代码来源:YamlFrontMatterTest.java

示例15: visitorIgnoresOtherCustomNodes

import org.commonmark.node.Node; //导入依赖的package包/类
@Test
public void visitorIgnoresOtherCustomNodes() {
    final String input = "---" +
            "\nhello: world" +
            "\n---" +
            "\n";

    YamlFrontMatterVisitor visitor = new YamlFrontMatterVisitor();
    Node document = PARSER.parse(input);
    document.appendChild(new TestNode());
    document.accept(visitor);

    Map<String, List<String>> data = visitor.getData();
    assertEquals(1, data.size());
    assertTrue(data.containsKey("hello"));
    assertEquals(Collections.singletonList("world"), data.get("hello"));
}
 
开发者ID:atlassian,项目名称:commonmark-java,代码行数:18,代码来源:YamlFrontMatterTest.java


注:本文中的org.commonmark.node.Node类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。