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


Java Parser.parse方法代码示例

本文整理汇总了Java中org.commonmark.parser.Parser.parse方法的典型用法代码示例。如果您正苦于以下问题:Java Parser.parse方法的具体用法?Java Parser.parse怎么用?Java Parser.parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.commonmark.parser.Parser的用法示例。


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

示例1: render

import org.commonmark.parser.Parser; //导入方法依赖的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.parser.Parser; //导入方法依赖的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: MockBodyPost

import org.commonmark.parser.Parser; //导入方法依赖的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

示例4: ioReaderTest

import org.commonmark.parser.Parser; //导入方法依赖的package包/类
@Test
public void ioReaderTest() throws IOException {
    Parser parser = Parser.builder().build();

    InputStream input1 = SpecReader.getSpecInputStream();
    Node document1;
    try (InputStreamReader reader = new InputStreamReader(input1)) {
        document1 = parser.parseReader(reader);
    }

    String spec = SpecReader.readSpec();
    Node document2 = parser.parse(spec);

    HtmlRenderer renderer = HtmlRenderer.builder().escapeHtml(true).build();
    assertEquals(renderer.render(document2), renderer.render(document1));
}
 
开发者ID:atlassian,项目名称:commonmark-java,代码行数:17,代码来源:ParserTest.java

示例5: enabledBlockTypes

import org.commonmark.parser.Parser; //导入方法依赖的package包/类
@Test
public void enabledBlockTypes() {
    String given = "# heading 1\n\nnot a heading";

    Parser parser = Parser.builder().build(); // all core parsers by default
    Node document = parser.parse(given);
    assertThat(document.getFirstChild(), instanceOf(Heading.class));

    Set<Class<? extends Block>> headersOnly = new HashSet<>();
    headersOnly.add(Heading.class);
    parser = Parser.builder().enabledBlockTypes(headersOnly).build();
    document = parser.parse(given);
    assertThat(document.getFirstChild(), instanceOf(Heading.class));

    Set<Class<? extends Block>> noCoreTypes = new HashSet<>();
    parser = Parser.builder().enabledBlockTypes(noCoreTypes).build();
    document = parser.parse(given);
    assertThat(document.getFirstChild(), not(instanceOf(Heading.class)));
}
 
开发者ID:atlassian,项目名称:commonmark-java,代码行数:20,代码来源:ParserTest.java

示例6: indentation

import org.commonmark.parser.Parser; //导入方法依赖的package包/类
@Test
public void indentation() {
    String given = " - 1 space\n   - 3 spaces\n     - 5 spaces\n\t - tab + space";
    Parser parser = Parser.builder().build();
    Node document = parser.parse(given);

    assertThat(document.getFirstChild(), instanceOf(BulletList.class));

    Node list = document.getFirstChild(); // first level list
    assertEquals("expect one child", list.getFirstChild(), list.getLastChild());
    assertEquals("1 space", firstText(list.getFirstChild()));

    list = list.getFirstChild().getLastChild(); // second level list
    assertEquals("expect one child", list.getFirstChild(), list.getLastChild());
    assertEquals("3 spaces", firstText(list.getFirstChild()));

    list = list.getFirstChild().getLastChild(); // third level list
    assertEquals("5 spaces", firstText(list.getFirstChild()));
    assertEquals("tab + space", firstText(list.getFirstChild().getNext()));
}
 
开发者ID:atlassian,项目名称:commonmark-java,代码行数:21,代码来源:ParserTest.java

示例7: markdownToHtml

import org.commonmark.parser.Parser; //导入方法依赖的package包/类
/**
 * Converts a markdown buffer to a Html buffer
 * 
 * @param buffer
 * @return String
 */
private String markdownToHtml(String buffer) {
    Parser parser = Parser.builder().build();
    Node document = parser.parse(buffer);
    HtmlRenderer renderer = HtmlRenderer.builder().build();
    String asHtml = renderer.render(document);
    return asHtml;
}
 
开发者ID:VISNode,项目名称:VISNode,代码行数:14,代码来源:MarkdownViewer.java

示例8: mdToHtml

import org.commonmark.parser.Parser; //导入方法依赖的package包/类
/**
 * markdown转换为html
 *
 * @param markdown
 * @return
 */
public static String mdToHtml(String markdown) {
    if (StringUtils.isBlank(markdown)) {
        return "";
    }
    java.util.List<Extension> extensions = Arrays.asList(TablesExtension.create());
    Parser parser = Parser.builder().extensions(extensions).build();
    Node document = parser.parse(markdown);
    HtmlRenderer renderer = HtmlRenderer.builder().extensions(extensions).build();
    String content = renderer.render(document);
    content = Commons.emoji(content);
    return content;
}
 
开发者ID:ZHENFENG13,项目名称:My-Blog,代码行数:19,代码来源:TaleUtils.java

示例9: stripMdText

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

示例10: parseTest

import org.commonmark.parser.Parser; //导入方法依赖的package包/类
@Test
public void parseTest() throws Exception {
    Parser parser = new Parser.Builder().build();

    Node document = parser.parse(spec);

    assertNotNull(document);
}
 
开发者ID:atlassian,项目名称:commonmark-java,代码行数:9,代码来源:AndroidSupportTest.java

示例11: parseWithExtensionsTest

import org.commonmark.parser.Parser; //导入方法依赖的package包/类
private void parseWithExtensionsTest(Extension extension) throws Exception {
    Parser parser = Parser.builder()
            .extensions(Collections.singletonList(extension))
            .build();

    Node document = parser.parse(spec);
    assertNotNull(document);

    HtmlRenderer renderer = HtmlRenderer.builder()
            .extensions(Collections.singletonList(extension))
            .build();

    String renderedString = renderer.render(document);
    assertNotNull(renderedString);
}
 
开发者ID:atlassian,项目名称:commonmark-java,代码行数:16,代码来源:AndroidSupportTest.java

示例12: customBlockParserFactory

import org.commonmark.parser.Parser; //导入方法依赖的package包/类
@Test
public void customBlockParserFactory() {
    Parser parser = Parser.builder().customBlockParserFactory(new DashBlockParserFactory()).build();

    // The dashes would normally be a ThematicBreak
    Node document = parser.parse("hey\n\n---\n");

    assertThat(document.getFirstChild(), instanceOf(Paragraph.class));
    assertEquals("hey", ((Text) document.getFirstChild().getFirstChild()).getLiteral());
    assertThat(document.getLastChild(), instanceOf(DashBlock.class));
}
 
开发者ID:atlassian,项目名称:commonmark-java,代码行数:12,代码来源:ParserTest.java

示例13: parseAndRender

import org.commonmark.parser.Parser; //导入方法依赖的package包/类
@Test
public void parseAndRender() {
    Parser parser = Parser.builder().build();
    Node document = parser.parse("This is *Sparta*");
    HtmlRenderer renderer = HtmlRenderer.builder().escapeHtml(true).build();
    assertEquals("<p>This is <em>Sparta</em></p>\n", renderer.render(document));
}
 
开发者ID:atlassian,项目名称:commonmark-java,代码行数:8,代码来源:UsageExampleTest.java

示例14: addAttributes

import org.commonmark.parser.Parser; //导入方法依赖的package包/类
@Test
public void addAttributes() {
    Parser parser = Parser.builder().build();
    HtmlRenderer renderer = HtmlRenderer.builder()
            .attributeProviderFactory(new AttributeProviderFactory() {
                public AttributeProvider create(AttributeProviderContext context) {
                    return new ImageAttributeProvider();
                }
            })
            .build();

    Node document = parser.parse("![text](/url.png)");
    assertEquals("<p><img src=\"/url.png\" alt=\"text\" class=\"border\" /></p>\n",
            renderer.render(document));
}
 
开发者ID:atlassian,项目名称:commonmark-java,代码行数:16,代码来源:UsageExampleTest.java

示例15: customizeRendering

import org.commonmark.parser.Parser; //导入方法依赖的package包/类
@Test
public void customizeRendering() {
    Parser parser = Parser.builder().build();
    HtmlRenderer renderer = HtmlRenderer.builder()
            .nodeRendererFactory(new HtmlNodeRendererFactory() {
                public NodeRenderer create(HtmlNodeRendererContext context) {
                    return new IndentedCodeBlockNodeRenderer(context);
                }
            })
            .build();

    Node document = parser.parse("Example:\n\n    code");
    assertEquals("<p>Example:</p>\n<pre>code\n</pre>\n", renderer.render(document));
}
 
开发者ID:atlassian,项目名称:commonmark-java,代码行数:15,代码来源:UsageExampleTest.java


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