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


Java HtmlRenderer类代码示例

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


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

示例1: render

import org.commonmark.renderer.html.HtmlRenderer; //导入依赖的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.renderer.html.HtmlRenderer; //导入依赖的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.renderer.html.HtmlRenderer; //导入依赖的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.renderer.html.HtmlRenderer; //导入依赖的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: toHtml

import org.commonmark.renderer.html.HtmlRenderer; //导入依赖的package包/类
private String toHtml(boolean source) {
	Node astRoot = toAstRoot();
	if (astRoot == null)
		return "";

	HtmlRenderer.Builder builder = HtmlRenderer.builder()
			.extensions(MarkdownExtensions.getCommonmarkExtensions());
	if (!source)
		builder.attributeProviderFactory(new MyAttributeProvider());
	String html = builder.build().render(astRoot);

       for (PreviewRendererAddon addon : addons)
           html = addon.postRender(html, path);

       return html;
}
 
开发者ID:JFormDesigner,项目名称:markdown-writer-fx,代码行数:17,代码来源:CommonmarkPreviewRenderer.java

示例6: markdownToHtml

import org.commonmark.renderer.html.HtmlRenderer; //导入依赖的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

示例7: mdToHtml

import org.commonmark.renderer.html.HtmlRenderer; //导入依赖的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

示例8: stripMdText

import org.commonmark.renderer.html.HtmlRenderer; //导入依赖的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

示例9: test

import org.commonmark.renderer.html.HtmlRenderer; //导入依赖的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

示例10: extend

import org.commonmark.renderer.html.HtmlRenderer; //导入依赖的package包/类
@Override
public void extend(HtmlRenderer.Builder rendererBuilder) {
    rendererBuilder.nodeRendererFactory(new HtmlNodeRendererFactory() {
        @Override
        public NodeRenderer create(HtmlNodeRendererContext context) {
            return new StrikethroughHtmlNodeRenderer(context);
        }
    });
}
 
开发者ID:atlassian,项目名称:commonmark-java,代码行数:10,代码来源:StrikethroughExtension.java

示例11: extend

import org.commonmark.renderer.html.HtmlRenderer; //导入依赖的package包/类
@Override
public void extend(HtmlRenderer.Builder rendererBuilder) {
    rendererBuilder.nodeRendererFactory(new HtmlNodeRendererFactory() {
        @Override
        public NodeRenderer create(HtmlNodeRendererContext context) {
            return new InsNodeRenderer(context);
        }
    });
}
 
开发者ID:atlassian,项目名称:commonmark-java,代码行数:10,代码来源:InsExtension.java

示例12: extend

import org.commonmark.renderer.html.HtmlRenderer; //导入依赖的package包/类
@Override
public void extend(HtmlRenderer.Builder rendererBuilder) {
    rendererBuilder.attributeProviderFactory(new AttributeProviderFactory() {
        @Override
        public AttributeProvider create(AttributeProviderContext context) {
            return HeadingIdAttributeProvider.create(defaultId, idPrefix, idSuffix);
        }
    });
}
 
开发者ID:atlassian,项目名称:commonmark-java,代码行数:10,代码来源:HeadingAnchorExtension.java

示例13: buildRenderer

import org.commonmark.renderer.html.HtmlRenderer; //导入依赖的package包/类
private HtmlRenderer buildRenderer(String defaultId, String prefix, String suffix) {
    Extension ext = HeadingAnchorExtension.builder()
            .defaultId(defaultId)
            .idPrefix(prefix)
            .idSuffix(suffix)
            .build();
    return HtmlRenderer.builder()
            .extensions(Arrays.asList(ext))
            .build();
}
 
开发者ID:atlassian,项目名称:commonmark-java,代码行数:11,代码来源:HeadingAnchorConfigurationTest.java

示例14: testDefaultConfigurationHasNoAdditions

import org.commonmark.renderer.html.HtmlRenderer; //导入依赖的package包/类
@Test
public void testDefaultConfigurationHasNoAdditions() {
    HtmlRenderer renderer = HtmlRenderer.builder()
            .extensions(Arrays.asList(HeadingAnchorExtension.create()))
            .build();
    assertThat(doRender(renderer, "# "), equalTo("<h1 id=\"id\"></h1>\n"));
}
 
开发者ID:atlassian,项目名称:commonmark-java,代码行数:8,代码来源:HeadingAnchorConfigurationTest.java

示例15: htmlRendererTest

import org.commonmark.renderer.html.HtmlRenderer; //导入依赖的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.renderer.html.HtmlRenderer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。