本文整理汇总了Java中org.pegdown.PegDownProcessor类的典型用法代码示例。如果您正苦于以下问题:Java PegDownProcessor类的具体用法?Java PegDownProcessor怎么用?Java PegDownProcessor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PegDownProcessor类属于org.pegdown包,在下文中一共展示了PegDownProcessor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processBody
import org.pegdown.PegDownProcessor; //导入依赖的package包/类
@Override
public void processBody(final ParserContext context) {
String[] mdExts = context.getConfig().getStringArray("markdown.extensions");
int extensions = Extensions.NONE;
if (mdExts.length > 0) {
for (int index = 0; index < mdExts.length; index++) {
String ext = mdExts[index];
if (ext.startsWith("-")) {
ext = ext.substring(1);
extensions=removeExtension(extensions, extensionFor(ext));
} else {
if (ext.startsWith("+")) {
ext = ext.substring(1);
}
extensions=addExtension(extensions, extensionFor(ext));
}
}
}
long maxParsingTime = context.getConfig().getLong("markdown.maxParsingTimeInMillis", PegDownProcessor.DEFAULT_MAX_PARSING_TIME);
PegDownProcessor pegdownProcessor = new PegDownProcessor(extensions, maxParsingTime);
context.setBody(pegdownProcessor.markdownToHtml(context.getBody()));
}
示例2: 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;
}
示例3: MarkdownService
import org.pegdown.PegDownProcessor; //导入依赖的package包/类
public MarkdownService () {
markdownFileExtensions.add("md");
markdownFileExtensions.add("txt");
markdownFileExtensions.add("markdown");
processor = new PegDownProcessor(
Extensions.AUTOLINKS | Extensions.TABLES
| Extensions.FENCED_CODE_BLOCKS | Extensions.STRIKETHROUGH
| Extensions.ATXHEADERSPACE | Extensions.TASKLISTITEMS);
// read style sheet
InputStream inputStream = MarkdownService.class.getResourceAsStream(STYLE_SHEET_FILE);
StringWriter writer = new StringWriter();
try {
IOUtils.copy(inputStream, writer, "UTF-8");
styleSheet = writer.toString();
} catch (IOException e) {
e.printStackTrace();
}
}
示例4: check
import org.pegdown.PegDownProcessor; //导入依赖的package包/类
private void check(PegDownPlugins.Builder extraPluginsBuilder, String markdown, String expectedAst) {
Reference<Parser> parserRef = new Reference<Parser>();
PegDownPlugins plugins =
(extraPluginsBuilder == null ? PegDownPlugins.builder() : extraPluginsBuilder)
.withPlugin(GenericBoxPlugin.class, parserRef)
.build();
// ---
PegDownProcessor processor = new PegDownProcessor(Extensions.ALL, plugins);
parserRef.set(processor.parser);
RootNode rootNode = processor.parseMarkdown(normalize(markdown).toCharArray());
String s = dumpAST(rootNode);
System.out.println("GenericBoxPluginTest.check::" + s);
assertThat(normalize(s.trim())).isEqualTo(normalize(expectedAst));
}
示例5: check
import org.pegdown.PegDownProcessor; //导入依赖的package包/类
private void check(String markdown, String expectedAst) {
Reference<Parser> parserRef = new Reference<Parser>();
PegDownPlugins plugins =
PegDownPlugins.builder()
.withPlugin(LinkContentPlugin.class, parserRef)
.build();
// ---
PegDownProcessor processor = new PegDownProcessor(Extensions.ALL, plugins);
parserRef.set(processor.parser);
RootNode rootNode = processor.parseMarkdown(normalize(markdown).toCharArray());
String s = dumpAST(rootNode);
assertThat(normalize(s.trim())).isEqualTo(normalize(expectedAst));
}
示例6: attributesPlugin
import org.pegdown.PegDownProcessor; //导入依赖的package包/类
@Theory
public void attributesPlugin(@ForAll @InRange(minInt = 0, maxInt = 0x0000FFFF) int extensions) throws IOException {
String mkd = loadResource("attributesText-simple.md").trim();
String ast = loadResource("attributesText-simple.ast").trim();
PegDownPlugins plugins = PegDownPlugins
.builder()
.withPlugin(AttributesPlugin.class)
.build();
PegDownProcessor processor = new PegDownProcessor(extensions, plugins);
RootNode rootNode = processor.parseMarkdown(normalize(mkd).toCharArray());
String s = dumpAST(rootNode);
assertThat(normalize(s.trim())).isEqualTo(normalize(ast));
}
示例7: astBuild_simpleCase
import org.pegdown.PegDownProcessor; //导入依赖的package包/类
@Test
public void astBuild_simpleCase() throws IOException {
String mkd = loadResource("attributesText-simple.md").trim();
String ast = loadResource("attributesText-simple.ast").trim();
PegDownPlugins plugins = PegDownPlugins
.builder()
.withPlugin(AttributesPlugin.class)
.build();
PegDownProcessor processor = new PegDownProcessor(Extensions.ALL, plugins);
RootNode rootNode = processor.parseMarkdown(normalize(mkd).toCharArray());
String s = dumpAST(rootNode);
assertThat(normalize(s.trim())).isEqualTo(normalize(ast));
}
示例8: astBuild_advancedCase
import org.pegdown.PegDownProcessor; //导入依赖的package包/类
@Test
public void astBuild_advancedCase() throws IOException {
String mkd = loadResource("attributesText.md").trim();
String ast = loadResource("attributesText.ast").trim();
PegDownPlugins plugins = PegDownPlugins
.builder()
.withPlugin(AttributesPlugin.class)
.build();
PegDownProcessor processor = new PegDownProcessor(Extensions.ALL, plugins);
RootNode rootNode = processor.parseMarkdown(normalize(mkd).toCharArray());
String s = dumpAST(rootNode);
assertThat(normalize(s.trim())).isEqualTo(normalize(ast));
}
示例9: processString
import org.pegdown.PegDownProcessor; //导入依赖的package包/类
private void processString(String usecase, String mkd, Function<InvocationContext, InvocationContext> customizer) throws Exception {
Reference<Parser> parserRef = new Reference<Parser>();
ITextContext iTextContext = openDocument(usecase);
PegDownPlugins plugins = PegDownPlugins
.builder()
.withPlugin(AttributesPlugin.class)
.withPlugin(GenericBoxPlugin.class, parserRef)
.build();
PegDownProcessor processor = new PegDownProcessor(Extensions.ALL, plugins);
parserRef.set(processor.parser);
RootNode rootNode = processor.parseMarkdown(mkd.toCharArray());
InvocationContext context = customizer.apply(new InvocationContext(iTextContext));
if (context == null) {
fail("No context");
return;
}
context.process(0, rootNode);
context.flushPendingChapter();
iTextContext.close();
}
示例10: 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);
}
示例11: renderPage
import org.pegdown.PegDownProcessor; //导入依赖的package包/类
@RequestMapping(method = RequestMethod.GET)
public String renderPage(Model model) {
PegDownProcessor processor = new PegDownProcessor();
List<GameInfo> featuredGames = gameService.listFeaturedGames();
for (GameInfo featuredGame : featuredGames) {
String description = featuredGame.getDescription();
if (description.length() > 200) {
description = description.subSequence(0, 200) + "...";
}
featuredGame.setDescription(processor.markdownToHtml(description));
}
model.addAttribute("featuredGames", featuredGames);
return "explore";
}
示例12: 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;
}
示例13: 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);
}
示例14: 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);
}
示例15: process
import org.pegdown.PegDownProcessor; //导入依赖的package包/类
private void process(final char[] article) throws IOException, TranslationException {
handler = new EntryHandler(this, article);
MarkdownSerializer serializer = new MarkdownSerializer(handler);
PegDownProcessor processor = new PegDownProcessor(PARSER_OPTION);
astRoot = processor.parseMarkdown(article);
checkArgNotNull(astRoot, "astRoot");
astRoot.accept(serializer);
// If handler has a exception when process, finish() throws TranslationException
handler.finish();
}