本文整理汇总了Java中org.commonmark.renderer.html.HtmlRenderer.render方法的典型用法代码示例。如果您正苦于以下问题:Java HtmlRenderer.render方法的具体用法?Java HtmlRenderer.render怎么用?Java HtmlRenderer.render使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.commonmark.renderer.html.HtmlRenderer
的用法示例。
在下文中一共展示了HtmlRenderer.render方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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);
}
示例4: parseWithExtensionsTest
import org.commonmark.renderer.html.HtmlRenderer; //导入方法依赖的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);
}
示例5: attributeProviderIsApplied
import org.commonmark.renderer.html.HtmlRenderer; //导入方法依赖的package包/类
@Test
public void attributeProviderIsApplied() {
AttributeProviderFactory factory = new AttributeProviderFactory() {
@Override
public AttributeProvider create(AttributeProviderContext context) {
return new AttributeProvider() {
@Override
public void setAttributes(Node node, String tagName, Map<String, String> attributes) {
if (node instanceof TableBlock) {
attributes.put("test", "block");
} else if (node instanceof TableHead) {
attributes.put("test", "head");
} else if (node instanceof TableBody) {
attributes.put("test", "body");
} else if (node instanceof TableRow) {
attributes.put("test", "row");
} else if (node instanceof TableCell) {
attributes.put("test", "cell");
}
}
};
}
};
HtmlRenderer renderer = HtmlRenderer.builder()
.attributeProviderFactory(factory)
.extensions(EXTENSIONS)
.build();
String rendered = renderer.render(PARSER.parse("Abc|Def\n---|---\n1|2"));
assertThat(rendered, is("<table test=\"block\">\n" +
"<thead test=\"head\">\n" +
"<tr test=\"row\"><th test=\"cell\">Abc</th><th test=\"cell\">Def</th></tr>\n" +
"</thead>\n" +
"<tbody test=\"body\">\n" +
"<tr test=\"row\"><td test=\"cell\">1</td><td test=\"cell\">2</td></tr>\n" +
"</tbody>\n" +
"</table>\n"));
}
示例6: parseMarkdown2html
import org.commonmark.renderer.html.HtmlRenderer; //导入方法依赖的package包/类
public static String parseMarkdown2html(String markdown){
Parser parser = Parser.builder().build();
Node document = parser.parse(markdown);
HtmlRenderer renderer = HtmlRenderer.builder().build();
return renderer.render(document);
}
示例7: sendEmail
import org.commonmark.renderer.html.HtmlRenderer; //导入方法依赖的package包/类
private void sendEmail(String to, String name, Card createdCard, Board board, ProjectMailTicketConfig config, ProjectMailTicket ticketConfig) {
String cardId = board.getShortName() + "-" + createdCard.getSequence();
String subjectTemplate = "" + (ticketConfig.getNotificationOverride() ? ticketConfig.getSubject() : config.getSubject());
String bodyTemplate = "" + (ticketConfig.getNotificationOverride() ? ticketConfig.getBody() : config.getBody());
String subject = subjectTemplate.replaceAll("\\{\\{card}}", cardId);
String body = bodyTemplate.replaceAll("\\{\\{card}}", cardId).replaceAll("\\{\\{name}}", name != null ? name : to);
Parser parser = Parser.builder().build();
Node document = parser.parse(body);
HtmlRenderer htmlRenderer = HtmlRenderer.builder().build();
TextContentRenderer textRendered = TextContentRenderer.builder().build();
String htmlText = htmlRenderer.render(document);
String plainText = textRendered.render(document);
ProjectMailTicketConfigData configData = config.getConfig();
MailConfig mailConfig = new MailConfig(configData.getOutboundServer(),
configData.getOutboundPort(),
configData.getOutboundProtocol(),
configData.getOutboundUser(),
configData.getOutboundPassword(),
ticketConfig.getSendByAlias() ? ticketConfig.getAlias() : configData.getOutboundAddress(),
configData.getOutboundProperties());
mailConfig.send(to, subject, plainText, htmlText);
}
示例8: process
import org.commonmark.renderer.html.HtmlRenderer; //导入方法依赖的package包/类
public MarkdownProcessorResult process(String markdownContent, List<Visitor> visitors) {
List<Extension> extensions = Arrays.asList(TablesExtension.create(), YamlFrontMatterExtension.create());
Parser parser = Parser.builder().extensions(extensions).build();
Node document = parser.parse(markdownContent);
YamlFrontMatterVisitor yamlVisitor = new YamlFrontMatterVisitor();
document.accept(yamlVisitor);
Set<String> linkTargets = new HashSet<>();
// Modify listing headings
for (Visitor visitor : visitors) {
document.accept(visitor); // new NavigationLinkInjector(siblingPages, subCategories));
}
// Fix links to *.md to go to *.html instead
document.accept(new AbstractVisitor() {
@Override
public void visit(Link link) {
URI uri = URI.create(link.getDestination());
linkTargets.add(link.getDestination());
link.setDestination(MarkdownUtils.renameFilenameForMarkdownPage(link.getDestination()));
visitChildren(link);
}
});
MarkdownTocGenerator tocGenerator = new MarkdownTocGenerator();
HtmlRenderer renderer = HtmlRenderer.builder().extensions(extensions).attributeProviderFactory(new AttributeProviderFactory() {
@Override
public AttributeProvider create(AttributeProviderContext context) {
return tocGenerator;
}
}).build();
String renderedContent = renderer.render(document);
MarkdownProcessorResult result = new MarkdownProcessorResult(renderedContent, tocGenerator.getToc(), yamlVisitor.getData());
result.getLinkTargets().addAll(linkTargets);
return result;
}
示例9: useCommonMark
import org.commonmark.renderer.html.HtmlRenderer; //导入方法依赖的package包/类
private String useCommonMark(String text) {
Parser parser = Parser.builder().build();
Node document = parser.parse(text);
HtmlRenderer renderer = HtmlRenderer.builder().build();
return renderer.render(document);
}
示例10: doRender
import org.commonmark.renderer.html.HtmlRenderer; //导入方法依赖的package包/类
private String doRender(HtmlRenderer renderer, String text) {
return renderer.render(PARSER.parse(text));
}
示例11: processCommonMark
import org.commonmark.renderer.html.HtmlRenderer; //导入方法依赖的package包/类
private String processCommonMark(String source) {
Parser parser = Parser.builder().build();
Node document = parser.parse(source);
HtmlRenderer renderer = HtmlRenderer.builder().build();
return renderer.render(document);
}
示例12: getHTMLUserGuide
import org.commonmark.renderer.html.HtmlRenderer; //导入方法依赖的package包/类
private String getHTMLUserGuide() {
StringBuilder result = new StringBuilder();
try(InputStream stream = CloudTrailViewer.class.getResourceAsStream("/docs/UserGuide.md")) {
if (stream != null) {
InputStreamReader io = new InputStreamReader(stream);
BufferedReader br = new BufferedReader(io);
String line;
while ((line = br.readLine()) != null) {
result.append(line).append("\n");
}
Parser parser = Parser.builder().build();
Node document = parser.parse(result.toString());
HtmlRenderer renderer = HtmlRenderer.builder().build();
return renderer.render(document);
} else {
DialogUtils.showAlertDialog("CloudTrail Viewer", "Application Error", "Unable to load User Guide.", Alert.AlertType.ERROR);
return null;
}
} catch (IOException ioe) {
DialogUtils.showAlertDialog("CloudTrail Viewer", "Application Error", "Unable to load User Guide.", Alert.AlertType.ERROR);
return null;
}
}