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


Java PegDownProcessor类代码示例

本文整理汇总了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()));
}
 
开发者ID:ghaseminya,项目名称:jbake-rtl-jalaali,代码行数:26,代码来源:MarkdownEngine.java

示例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;
}
 
开发者ID:daima,项目名称:solo-spring,代码行数:24,代码来源:Markdowns.java

示例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();
	}
}
 
开发者ID:windsource,项目名称:evernote-markdown-sync,代码行数:23,代码来源:MarkdownService.java

示例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));
}
 
开发者ID:Arnauld,项目名称:gutenberg,代码行数:20,代码来源:GenericBoxPluginTest.java

示例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));
}
 
开发者ID:Arnauld,项目名称:gutenberg,代码行数:19,代码来源:LinkContentPluginTest.java

示例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));
}
 
开发者ID:Arnauld,项目名称:gutenberg,代码行数:17,代码来源:ExtensionsCompatibilityPluginTest.java

示例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));
}
 
开发者ID:Arnauld,项目名称:gutenberg,代码行数:17,代码来源:AttributesPluginTest.java

示例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));
}
 
开发者ID:Arnauld,项目名称:gutenberg,代码行数:17,代码来源:AttributesPluginTest.java

示例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();
}
 
开发者ID:Arnauld,项目名称:gutenberg,代码行数:25,代码来源:PegdownPdfTest.java

示例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);
}
 
开发者ID:sillelien,项目名称:dollar,代码行数:18,代码来源:ParseDocs.java

示例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";
}
 
开发者ID:pillingworthz,项目名称:ifictionary,代码行数:18,代码来源:ExploreController.java

示例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;
}
 
开发者ID:StallionCMS,项目名称:stallion-core,代码行数:16,代码来源:Markdown.java

示例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);
}
 
开发者ID:marcobehler,项目名称:saito,代码行数:9,代码来源:MarkdownRenderer.java

示例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);
}
 
开发者ID:ops4j,项目名称:org.ops4j.ramler,代码行数:9,代码来源:MarkdownTest.java

示例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();
}
 
开发者ID:miurahr,项目名称:omegat-markdown-plugin,代码行数:11,代码来源:OmegatMarkdownFilter.java


注:本文中的org.pegdown.PegDownProcessor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。