本文整理汇总了Java中org.pegdown.PegDownProcessor.markdownToHtml方法的典型用法代码示例。如果您正苦于以下问题:Java PegDownProcessor.markdownToHtml方法的具体用法?Java PegDownProcessor.markdownToHtml怎么用?Java PegDownProcessor.markdownToHtml使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.pegdown.PegDownProcessor
的用法示例。
在下文中一共展示了PegDownProcessor.markdownToHtml方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toHTML
import org.pegdown.PegDownProcessor; //导入方法依赖的package包/类
/**
* Converts the specified markdown text to HTML.
*
* @param markdownText
* the specified markdown text
* @return converted HTML, returns {@code null} if the specified markdown
* text is "" or {@code null}, returns "Markdown error" if exception
*/
public static String toHTML(final String markdownText) {
if (StringUtils.isBlank(markdownText)) {
return "";
}
final PegDownProcessor pegDownProcessor = new PegDownProcessor(
Extensions.ALL_OPTIONALS | Extensions.ALL_WITH_OPTIONALS, 5000);
String ret = pegDownProcessor.markdownToHtml(markdownText);
if (!StringUtils.startsWith(ret, "<p>")) {
ret = "<p>" + ret + "</p>";
}
return ret;
}
示例2: parseDoc
import org.pegdown.PegDownProcessor; //导入方法依赖的package包/类
private static void parseDoc(@NotNull String page, @NotNull File outDir) throws IOException {
outDir.mkdirs();
String source = CharStreams.toString(
new InputStreamReader(ParseDocs.class.getResourceAsStream("/pages/" + page + ".md")));
String toParse;
if (source.startsWith("#!")) {
toParse = "\n" + source.substring(source.indexOf("\n"));
} else {
toParse = source;
}
new DollarParserImpl(new ParserOptions()).parseMarkdown(toParse);
PegDownProcessor pegDownProcessor = new PegDownProcessor(Extensions.FENCED_CODE_BLOCKS);
String result = pegDownProcessor.markdownToHtml(toParse);
Files.write(new File(outDir, page + ".html").toPath(), result.getBytes());
Files.write(new File(outDir, page + ".md").toPath(), toParse.getBytes());
System.exit(0);
}
示例3: process
import org.pegdown.PegDownProcessor; //导入方法依赖的package包/类
public String process(String itemContent) {
itemContent = new MarkdownFootnotesProcessor(itemContent).process();
ParsedContent parsed = parseOutRawHtml(itemContent);
PegDownProcessor pegdownProcessor = new PegDownProcessor(
Extensions.FENCED_CODE_BLOCKS |
Extensions.AUTOLINKS |
Extensions.STRIKETHROUGH |
Extensions.TABLES |
Extensions.QUOTES |
Extensions.SMARTS
);
itemContent = pegdownProcessor.markdownToHtml(parsed.content);
itemContent = swapInRawHtml(itemContent, parsed);
return itemContent;
}
示例4: render
import org.pegdown.PegDownProcessor; //导入方法依赖的package包/类
@Override
public String render(final Template template, final Model model) {
final PegDownProcessor pegDownProcessor = new PegDownProcessor();
final String markdown = template.getContent().getText();
final String html = pegDownProcessor.markdownToHtml(markdown);
return freemarkerRenderer.renderLayout(template, html, model);
}
示例5: shouldHighlightMarkdown
import org.pegdown.PegDownProcessor; //导入方法依赖的package包/类
@Test
public void shouldHighlightMarkdown() throws IOException {
PegDownProcessor processor = new PegDownProcessor(Extensions.FENCED_CODE_BLOCKS);
byte[] bytes = Files.readAllBytes(Paths.get("src/test/resources/markdown", "java1.md"));
String markdown = new String(bytes, StandardCharsets.UTF_8);
String html = processor.markdownToHtml(markdown);
System.out.println(html);
}
示例6: compile
import org.pegdown.PegDownProcessor; //导入方法依赖的package包/类
public static String compile(String src) {
PegDownProcessor processor = new PegDownProcessor(Extensions.AUTOLINKS | Extensions.FENCED_CODE_BLOCKS);
String replaced = expandSpaceForLi(src);
String html = processor.markdownToHtml(replaced);
String cleanedHtml = Jsoup.clean(html, Whitelist.relaxed());
return cleanedHtml;
}
示例7: usePegDown
import org.pegdown.PegDownProcessor; //导入方法依赖的package包/类
private String usePegDown(String text) {
PegDownProcessor pegdown = new PegDownProcessor();
return pegdown.markdownToHtml(text);
}
示例8: fileResourceProcessor
import org.pegdown.PegDownProcessor; //导入方法依赖的package包/类
private static Function<FileResourceParameters, FileResourceProcessorOutput> fileResourceProcessor() {
PegDownProcessor pegDownProcessor = new PegDownProcessor(Extensions.ALL);
return params -> new FileResourceProcessorOutput(pegDownProcessor.markdownToHtml(params.fileResource.getContent().orElseThrow(IllegalArgumentException::new)), params.fileResource.getPath(), "markdown", params.locale);
}