本文整理汇总了Java中org.pegdown.LinkRenderer类的典型用法代码示例。如果您正苦于以下问题:Java LinkRenderer类的具体用法?Java LinkRenderer怎么用?Java LinkRenderer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LinkRenderer类属于org.pegdown包,在下文中一共展示了LinkRenderer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: markdownToHtml
import org.pegdown.LinkRenderer; //导入依赖的package包/类
/**
* Convert Markdown into HTML (just the body content) with inline styles
*
* @param markdown Markdown to convert into HTML
* @return String containing HTML (just the body content)
* @throws MarkdownException
*/
String markdownToHtml(String markdown) throws MarkdownException {
Map<String, VerbatimSerializer> verbatimSerializers = new HashMap<>();
verbatimSerializers.put(MyCustomVerbatimSerializer.DEFAULT, MyCustomVerbatimSerializer.INSTANCE);
String htmlBody = processor.markdownToHtml(markdown.toCharArray(), new LinkRenderer(), verbatimSerializers);
LOG.debug("Body before styles: {}",htmlBody);
String htmlWithStyleInline = "";
try {
htmlWithStyleInline = new HtmlStyleSheetInliner().inlineStyleSheet(htmlBody, styleSheet);
} catch (SAXException | IOException | TransformerException e) {
e.printStackTrace();
throw new MarkdownException("Could not turn Markdown to HTML");
}
LOG.debug("Body after styles: {}",htmlWithStyleInline);
return htmlWithStyleInline;
}
示例2: markdownToDocHtml
import org.pegdown.LinkRenderer; //导入依赖的package包/类
public byte[] markdownToDocHtml(String md, String charEnc) throws UnsupportedEncodingException {
RootNode root = parseMarkdown(md);
String title = findTitle(root);
StringBuilder html = new StringBuilder();
html.append("<html>");
html.append("<head>");
if (!Strings.isNullOrEmpty(title)) {
html.append("<title>").append(title).append("</title>");
}
html.append("<style type=\"text/css\">\n");
if (css != null) {
html.append(css);
} else {
html.append(readCSS());
}
html.append("\n</style>");
html.append("</head>");
html.append("<body>\n");
html.append(new ToHtmlSerializer(new LinkRenderer()).toHtml(root));
html.append("\n</body></html>");
return html.toString().getBytes(charEnc);
}
示例3: visit
import org.pegdown.LinkRenderer; //导入依赖的package包/类
@Override
public void visit(HeaderNode node) {
String tag = "h" + node.getLevel();
String title = printChildrenToString(node);
LinkRenderer.Rendering anchorLink = createAnchorLink(title);
printer.print('<').print(tag).print('>');
printLink(anchorLink);
visitChildren(node);
printer.print('<').print('/').print(tag).print('>');
}
示例4: renderToHtml
import org.pegdown.LinkRenderer; //导入依赖的package包/类
@Override
public String renderToHtml(String markdownSource) {
// synchronizing on pegdown instance since neither the processor nor the underlying parser is thread-safe.
synchronized (pegdown) {
RootNode astRoot = pegdown.parseMarkdown(markdownSource.toCharArray());
MarkdownToHtmlSerializer serializer = new MarkdownToHtmlSerializer(new LinkRenderer(),
Collections.singletonMap(VerbatimSerializer.DEFAULT, PrettifyVerbatimSerializer.INSTANCE));
return serializer.toHtml(astRoot);
}
}
示例5: markdownToHtml
import org.pegdown.LinkRenderer; //导入依赖的package包/类
@Override
public String markdownToHtml(char[] markdownSource,
LinkRenderer linkRenderer,
Map<String, VerbatimSerializer> verbatimSerializerMap) {
try {
RootNode astRoot = parseMarkdown(markdownSource);
return new ToHtmlNoLinkSerializer(linkRenderer,
verbatimSerializerMap).toHtml(astRoot);
} catch (ParsingTimeoutException e) {
return null;
}
}
示例6: toHtml
import org.pegdown.LinkRenderer; //导入依赖的package包/类
@Override
public String toHtml(String source) {
try {
Map<String, VerbatimSerializer> serializers = new HashMap<>();
PlantUmlVerbatimSerializer.addToMap(serializers);
LinkRenderer linkRenderer = new TypeLinkRenderer();
return processor.markdownToHtml(source, linkRenderer, serializers);
} catch (Exception e) {
LOGGER.error("Could not convert given source to markdown: {}", source, e);
return source;
}
}
示例7: printAnchorLink
import org.pegdown.LinkRenderer; //导入依赖的package包/类
protected void printAnchorLink(LinkRenderer.Rendering rendering) {
printer.print('<').print('a');
printAttribute("href", rendering.href);
for (LinkRenderer.Attribute attr : rendering.attributes) {
printAttribute(attr.name, attr.value);
}
printer.print('>').print("<span class=\"octicon octicon-link\"></span>").print(rendering.text).print("</a>");
}
示例8: printLink
import org.pegdown.LinkRenderer; //导入依赖的package包/类
@Override
protected void printLink(Rendering rendering) {
printer.print('<').print('a');
printAttribute("href", rendering.href);
rendering.withAttribute("target", "_blank");
for (LinkRenderer.Attribute attr : rendering.attributes) {
printAttribute(attr.name, attr.value);
}
printer.print('>').print(rendering.text).print("</a>");
}
示例9: printImageTag
import org.pegdown.LinkRenderer; //导入依赖的package包/类
protected void printImageTag(LinkRenderer.Rendering rendering) {
printer.print("<img");
printAttribute("src", rendering.href);
printAttribute("title", rendering.text);
printAttribute("class", "chat-image");
for (LinkRenderer.Attribute attr : rendering.attributes) {
printAttribute(attr.name, attr.value);
}
printer.print("\"/>");
}
示例10: markdownToHtml
import org.pegdown.LinkRenderer; //导入依赖的package包/类
public String markdownToHtml(char[] markdownSource, LinkRenderer linkRenderer, Map<String, VerbatimSerializer> verbatimSerializerMap) {
try {
RootNode astRoot = parseMarkdown(markdownSource);
return new NS2GToHtmlSerializer(linkRenderer, verbatimSerializerMap).toHtml(astRoot);
} catch (ParsingTimeoutException e) {
return null;
}
}
示例11: formatHtml
import org.pegdown.LinkRenderer; //导入依赖的package包/类
private String formatHtml(String text) {
if (BricABrac.isBlank(text)) {
return "";
}
PegDownProcessor markdownProcessor = configuration.getMarkdownProcessor();
RootNode astRoot = markdownProcessor.parseMarkdown(text.toCharArray());
//astRoot.accept(Visitors.dump());
List<ToHtmlSerializerPlugin> htmlPlugins = configuration.htmlSerializerPlugins();
ToHtmlSerializer htmlSerializer = new ToHtmlSerializer(new LinkRenderer(), htmlPlugins);
return htmlSerializer.toHtml(astRoot);
}
示例12: getLinkRenderer
import org.pegdown.LinkRenderer; //导入依赖的package包/类
/**
* Gets the link renderer.
*
* @return The link renderer.
*/
public LinkRenderer getLinkRenderer() {
if ( linkRenderer == null ) {
linkRenderer = new DocletLinkRenderer();
}
return linkRenderer;
}
示例13: printLink
import org.pegdown.LinkRenderer; //导入依赖的package包/类
@Override
protected void printLink(LinkRenderer.Rendering rendering)
{
printer.print('<').print('a');
printAttribute("href", rendering.href);
for (LinkRenderer.Attribute attr : rendering.attributes) {
printAttribute(attr.name, attr.value);
}
printAttribute("target", "_blank");
printer.print('>').print(rendering.text).print("</a>");
}
示例14: MarkdownToHtmlSerializer
import org.pegdown.LinkRenderer; //导入依赖的package包/类
public MarkdownToHtmlSerializer(final LinkRenderer linkRenderer, final Map<String, VerbatimSerializer> verbatimSerializers) {
super(linkRenderer, verbatimSerializers);
}
示例15: createAnchorLink
import org.pegdown.LinkRenderer; //导入依赖的package包/类
private LinkRenderer.Rendering createAnchorLink(String title) {
String cleanedTitle = title.toLowerCase().replace("\n", " ").replaceAll("[^a-z\\d\\s]", " ");
String slug = StringUtils.arrayToDelimitedString(StringUtils.tokenizeToStringArray(cleanedTitle, " "), "-");
return new LinkRenderer.Rendering("#"+slug, "").withAttribute("class","anchor").withAttribute("name", slug);
}