本文整理汇总了Java中com.vladsch.flexmark.parser.Parser类的典型用法代码示例。如果您正苦于以下问题:Java Parser类的具体用法?Java Parser怎么用?Java Parser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Parser类属于com.vladsch.flexmark.parser包,在下文中一共展示了Parser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseBuildAndRender
import com.vladsch.flexmark.parser.Parser; //导入依赖的package包/类
private String parseBuildAndRender(String text) {
Parser parser = Parser.builder(OPTIONS)
.extensions(EXTENSIONS)
.build();
HtmlRenderer renderer = HtmlRenderer.builder(OPTIONS)
.escapeHtml(mEscapeHtml)
.attributeProviderFactory(new IndependentAttributeProviderFactory() {
@Override
public AttributeProvider create(NodeRendererContext context) {
return new CustomAttributeProvider();
}
})
.nodeRendererFactory(new NodeRendererFactoryImpl())
.extensions(EXTENSIONS)
.build();
return renderer.render(parser.parse(text));
}
示例2: save
import com.vladsch.flexmark.parser.Parser; //导入依赖的package包/类
@Override
public JSONObject save(DocModel doc, boolean markdown) {
DocModel model = validator.isEmpty(doc.getId()) ? new DocModel() : findById(doc.getId());
model.setKey(doc.getKey());
model.setOwner(validator.isEmpty(doc.getOwner()) ? "" : doc.getOwner());
model.setAuthor(userHelper.id());
model.setScoreMin(doc.getScoreMin());
model.setScoreMax(doc.getScoreMax());
model.setSort(doc.getSort());
model.setSubject(doc.getSubject());
model.setImage(doc.getImage());
model.setThumbnail(doc.getThumbnail());
model.setSummary(doc.getSummary());
model.setLabel(doc.getLabel());
model.setSource(doc.getSource());
model.setContent(markdown ? HtmlRenderer.builder().build().render(Parser.builder().build().parse(doc.getSource())).trim() : doc.getSource());
model.setTime(dateTime.now());
model.setAudit(defaultAudit);
docDao.save(model);
clearCache(model.getId());
return toJson(model);
}
示例3: MarkdownCompiler
import com.vladsch.flexmark.parser.Parser; //导入依赖的package包/类
@Inject
public MarkdownCompiler(Set<Extension> extensionSet, Set<MutableDataSet> injectedOptions) {
super(900);
MutableDataSet options = new MutableDataSet();
options.set(HtmlRenderer.GENERATE_HEADER_ID, true);
options.set(HtmlRenderer.RENDER_HEADER_ID, true);
options.set(Parser.EXTENSIONS, extensionSet);
for(MutableDataSet injectedOption : injectedOptions) {
options.setAll(injectedOption);
}
parser = Parser.builder(options).build();
renderer = HtmlRenderer.builder(options).build();
}
示例4: format
import com.vladsch.flexmark.parser.Parser; //导入依赖的package包/类
private static String format(String input, int wrapLength) {
// parse markdown
Document document = Parser.builder().build().parse(input);
// format
List<Pair<Paragraph, String>> formattedParagraphs = new SmartFormat(null, null)
.formatParagraphs(document, wrapLength);
// build result
StringBuilder output = new StringBuilder(input);
for (int i = formattedParagraphs.size() - 1; i >= 0; i--) {
Pair<Paragraph, String> pair = formattedParagraphs.get(i);
Paragraph paragraph = pair.getFirst();
String newText = pair.getSecond();
int startOffset = paragraph.getStartOffset();
int endOffset = paragraph.getEndOffset();
if (paragraph.getChars().endsWith("\n"))
endOffset--;
output.replace(startOffset, endOffset, newText);
}
return output.toString();
}
示例5: 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;
}
示例6: 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());
}
示例7: Markdown2Html
import com.vladsch.flexmark.parser.Parser; //导入依赖的package包/类
public Markdown2Html() {
MutableDataSet options = new MutableDataSet();
// uncomment to set optional extensions
//options.set(Parser.EXTENSIONS, Arrays.asList(TablesExtension.create(), StrikethroughExtension.create()));
// uncomment to convert soft-breaks to hard breaks
//options.set(HtmlRenderer.SOFT_BREAK, "<br />\n");
// options.set(HtmlRenderer.SOFT_BREAK, "<br />\n");
options.set(HtmlRenderer.ESCAPE_HTML_BLOCKS, true);
this.parser = Parser.builder(options).build();
}
示例8: MarkdownAssetsServlet
import com.vladsch.flexmark.parser.Parser; //导入依赖的package包/类
/**
* Construct a {@link MarkdownAssetsServlet} configured with provided parameters, having a wrapped default
* {@link AssetServlet} for fulfilling non-markdown asset requests.
* <p>
* {@code MarkdownAssetsServlet} and {@link AssetServlet} serve static assets loaded from {@code resourceURL}
* (typically a file: or jar: URL). The assets are served at URIs rooted at {@code uriPath}. For
* example, given a {@code resourceURL} of {@code "file:/data/assets"} and a {@code uriPath} of
* {@code "/js"}, an {@code AssetServlet} would serve the contents of {@code
* /data/assets/example.js} in response to a request for {@code /js/example.js}. If a directory
* is requested and {@code indexFile} is defined, then {@code AssetServlet} will attempt to
* serve a file with that name in that directory.
* @param resourcePath the base URL from which assets are loaded
* @param uriPath the URI path fragment in which all requests are rooted
* @param indexFile the filename to use when directories are requested
* @param defaultCharset the default character set
* @param configuration environment-specific configuration properties
* @param extensions Flexmark-Java markdown rendering extensions to use
* @param options Flexmark-Java markdown rendering options
* @param cacheBuilderSpec {@link CacheBuilderSpec} for rendered pages
*/
public MarkdownAssetsServlet(@NotNull String resourcePath,
@NotNull String uriPath,
@NotNull String indexFile,
@NotNull Charset defaultCharset,
@NotNull MarkdownAssetsConfiguration configuration,
@NotNull List<Extension> extensions,
@NotNull DataHolder options,
@NotNull CacheBuilderSpec cacheBuilderSpec) {
this.resourcePath = resourcePath;
this.uriPath = uriPath;
this.indexFile = indexFile;
this.defaultCharset = defaultCharset;
this.configuration = configuration;
parser = Parser.builder(options).extensions(extensions).build();
renderer = HtmlRenderer.builder(options).extensions(extensions).build();
assetServlet = new AssetServlet(resourcePath, uriPath, indexFile, defaultCharset);
pageCache = CacheBuilder.from(cacheBuilderSpec)
.build(new CacheLoader<URL, CachedPage>() {
@Override
public CachedPage load(@NotNull URL key) throws Exception {
return renderPage(key);
}
});
try {
URL resource = this.getClass().getResource(resourcePath);
Preconditions.checkNotNull(resource, "Resource root URL (" + resourcePath + ") was not found");
resourceRootURL = resource.toURI();
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Resource root URL (" + resourcePath + ") was ind", e);
}
}
示例9: parseBuildAndRender
import com.vladsch.flexmark.parser.Parser; //导入依赖的package包/类
private String parseBuildAndRender(String text) {
Parser parser = Parser.builder(OPTIONS).extensions(EXTENSIONS).build();
HtmlRenderer renderer = HtmlRenderer.builder(OPTIONS).escapeHtml(mEscapeHtml)
.attributeProviderFactory(new IndependentAttributeProviderFactory() {
public AttributeProvider create(NodeRendererContext context) {
return new CustomAttributeProvider();
}
}).nodeRendererFactory(
new MarkdownView.NodeRendererFactoryImpl())
.extensions(EXTENSIONS).build();
return renderer.render(parser.parse(text));
}
示例10: 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);
}
示例11: parseMarkdown
import com.vladsch.flexmark.parser.Parser; //导入依赖的package包/类
private Node parseMarkdown(String text) {
if (parser == null) {
parser = Parser.builder()
.extensions(MarkdownExtensions.getFlexmarkExtensions(Options.getMarkdownRenderer()))
.build();
}
return parser.parse(text);
}
示例12: getMarkdownOptions
import com.vladsch.flexmark.parser.Parser; //导入依赖的package包/类
private static MutableDataHolder getMarkdownOptions() {
return new MutableDataSet()
.set(HtmlRenderer.ESCAPE_HTML, true)
.set(EmojiExtension.USE_IMAGE_URLS, true)
// for full GFM table compatibility add the following table extension options:
.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(Parser.EXTENSIONS, Arrays.asList(TablesExtension.create(), EmojiExtension.create(),
StrikethroughExtension.create(), TaskListExtension.create()));
}
示例13: 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));
}
示例14: generateDoc
import com.vladsch.flexmark.parser.Parser; //导入依赖的package包/类
@Override
public String generateDoc(PsiElement element, @Nullable PsiElement originalElement)
{
if(!(element instanceof TaskPsiElement))
{
return null;
}
final Task task = ((TaskPsiElement) element).getTask();
final StringBuilder builder = new StringBuilder();
builder.append("<b>Summary:</b> ").append(task.getSummary()).append("<br>");
builder.append("<b>Id:</b> ").append(task.getId()).append("<br>");
if(task.getCreated() != null)
{
builder.append("<b>Created at:</b> ").append(task.getCreated()).append("<br>");
}
if(task.getUpdated() != null)
{
builder.append("<b>Updated at:</b> ").append(task.getUpdated()).append("<br>");
}
final String description = task.getDescription();
if(description != null)
{
Parser parser = Parser.builder().build();
HtmlRenderer renderer = HtmlRenderer.builder().build();
builder.append("<b>Description:</b><br>").append(renderer.render(parser.parse(description)));
}
for(Comment comment : task.getComments())
{
comment.appendTo(builder);
}
return XmlStringUtil.wrapInHtml(builder);
}
示例15: setExtensions
import com.vladsch.flexmark.parser.Parser; //导入依赖的package包/类
public void setExtensions(List<Extension> extensions) {
options.remove(EXTENSIONS);
options.set(EXTENSIONS, extensions);
logger.debug("Resetting markdown parser extensions: {}", options.get(Parser.EXTENSIONS).toString());
}