本文整理汇总了Java中com.vladsch.flexmark.parser.Parser.parse方法的典型用法代码示例。如果您正苦于以下问题:Java Parser.parse方法的具体用法?Java Parser.parse怎么用?Java Parser.parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.vladsch.flexmark.parser.Parser
的用法示例。
在下文中一共展示了Parser.parse方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: render
import com.vladsch.flexmark.parser.Parser; //导入方法依赖的package包/类
@Override
public String render(String markdown, @Nullable String baseUrl, boolean postProcess) {
Preconditions.checkArgument(baseUrl == null || baseUrl.startsWith("/"));
List<Extension> extensions = new ArrayList<>();
extensions.add(AnchorLinkExtension.create());
extensions.add(TablesExtension.create());
extensions.add(TaskListExtension.create());
extensions.add(DefinitionExtension.create());
extensions.add(TocExtension.create());
extensions.add(AutolinkExtension.create());
extensions.add(new UrlResolveExtension());
extensions.addAll(contributedExtensions);
MutableDataHolder options = new MutableDataSet()
.set(HtmlRenderer.GENERATE_HEADER_ID, true)
.set(AnchorLinkExtension.ANCHORLINKS_SET_NAME, true)
.set(AnchorLinkExtension.ANCHORLINKS_ANCHOR_CLASS, "header-anchor")
.set(AnchorLinkExtension.ANCHORLINKS_TEXT_SUFFIX, "<i class='fa fa-link'></i>")
.set(Parser.SPACE_IN_LINK_URLS, true)
.setFrom(ParserEmulationProfile.GITHUB_DOC)
.set(TablesExtension.COLUMN_SPANS, false)
.set(TablesExtension.APPEND_MISSING_COLUMNS, true)
.set(TablesExtension.DISCARD_EXTRA_COLUMNS, true)
.set(TablesExtension.HEADER_SEPARATOR_COLUMN_MATCH, true)
.set(UrlResolveExtension.BASE_URL, baseUrl)
.set(Parser.EXTENSIONS, extensions);
Parser parser = Parser.builder(options).build();
HtmlRenderer htmlRenderer = HtmlRenderer.builder(options).build();
Node document = parser.parse(markdown);
String html = htmlRenderer.render(document);
if (postProcess)
html = postProcess(html);
return html;
}
示例2: test
import com.vladsch.flexmark.parser.Parser; //导入方法依赖的package包/类
@Test
void test() throws IOException {
Parser p = Parser.builder().build();
Node document = p.parse("# Heading\n" +
"Paragraph with\n" +
"multiple lines and [link](example.com)");
AnnotatedTextBuildingVisitor visitor = new AnnotatedTextBuildingVisitor();
visitor.visit((Document) document);
AnnotatedText text = visitor.getText();
Assertions.assertEquals("Heading\nParagraph with multiple lines and link", text.getPlainText());
}
示例3: parseMarkdown
import com.vladsch.flexmark.parser.Parser; //导入方法依赖的package包/类
private Node parseMarkdown(String text) {
for (PreviewRendererAddon addon : addons)
text = addon.preParse(text, path);
Parser parser = Parser.builder()
.extensions(MarkdownExtensions.getFlexmarkExtensions())
.build();
return parser.parse(text);
}
示例4: processBody
import com.vladsch.flexmark.parser.Parser; //导入方法依赖的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));
}
}
}
DataHolder options = PegdownOptionsAdapter.flexmarkOptions(
extensions
);
Parser parser = Parser.builder(options).build();
HtmlRenderer renderer = HtmlRenderer.builder(options).build();
Node document = parser.parse(context.getBody());
context.setBody(renderer.render(document));
}
示例5: markdownToHtml
import com.vladsch.flexmark.parser.Parser; //导入方法依赖的package包/类
/**
* Generate HTML from markdown
* @param markdown (String)
* @return String (HTML)
*/
public String markdownToHtml(String markdown){
Parser parser = Parser.builder(options).extensions(extensions).build();
HtmlRenderer renderer = HtmlRenderer.builder(options).extensions(extensions).build();
Node document = parser.parse(markdown);
return renderer.render(document);
}