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


Java Parser类代码示例

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


Parser类属于org.commonmark.parser包,在下文中一共展示了Parser类的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: generateContents

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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: createParser

import org.commonmark.parser.Parser; //导入依赖的package包/类
/**
 * Helper method to obtain a Parser with registered strike-through &amp; table extensions
 * &amp; task lists (added in 1.0.1)
 *
 * @return a Parser instance that is supported by this library
 * @since 1.0.0
 */
@NonNull
public static Parser createParser() {
    return new Parser.Builder()
            .extensions(Arrays.asList(
                    StrikethroughExtension.create(),
                    TablesExtension.create(),
                    TaskListExtension.create()
            ))
            .build();
}
 
开发者ID:noties,项目名称:Markwon,代码行数:18,代码来源:Markwon.java

示例12: test

import org.commonmark.parser.Parser; //导入依赖的package包/类
@Test
public void test() {
       String testInputDocument = "Foo\n"
       		+ "# Generated Section - Pages\n"
       		+ "Bar\n"
       		+ "## Generated Section - Categories\n";

       String testOutputDocument = "Foo\n"
       		+ "# Pages\n"
       		+ "* [Foo](foo.md)\n"
       		+ "* [Bar](bar.md)\n"
       		+ "\nBar\n"
       		+ "## Categories\n"
       		+ "* [Goo](goo/index.md)\n"
       		+ "* [Gar](gar/index.md)\n";

       Node testDocument = Parser.builder().build().parse(testInputDocument);

       Node expectedDocument = Parser.builder().build().parse(testOutputDocument);

       List<String> siblingPages = Arrays.asList(new String[]{"foo.md", "bar.md"});
       List<String> subCategories = Arrays.asList(new String[]{"goo", "gar"});
       
       NavigationLinkInjector navigationLinkInjector = new NavigationLinkInjector(
           Paths.get("/example/example.md"), Paths.get("/example"),
           siblingPages, subCategories);

       testDocument.accept(navigationLinkInjector);
       
       HtmlRenderer renderer = HtmlRenderer.builder().build();
       
       Assert.assertEquals(renderer.render(expectedDocument), renderer.render(testDocument));
}
 
开发者ID:mattsheppard,项目名称:markdown-static-site-generator,代码行数:34,代码来源:NavigationLinkInjectorTest.java

示例13: setData

import org.commonmark.parser.Parser; //导入依赖的package包/类
public void setData(javafx.scene.Scene parent, String markdown) {
    parentScene = parent;
    
    // this really should be fast enough that I don't need to make it
    // asynchronous.... the notes aren't going to be that big.
    Parser parser = Parser.builder().build();
    HtmlRenderer renderer = HtmlRenderer.builder().build();
    String html = renderer.render(parser.parse(markdown));
   
    webview.getEngine().loadContent(html);
    
}
 
开发者ID:rwtodd,项目名称:spritz_cipher,代码行数:13,代码来源:RenderedWinController.java

示例14: 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

示例15: htmlRendererTest

import org.commonmark.parser.Parser; //导入依赖的package包/类
@Test
public void htmlRendererTest() throws Exception {
    Parser parser = Parser.builder().build();
    HtmlRenderer renderer = HtmlRenderer.builder().build();

    String renderedString = renderer.render(parser.parse(spec));

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


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