com.vladsch.flexmark.html.HtmlRenderer Java Examples
The following examples show how to use
com.vladsch.flexmark.html.HtmlRenderer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MarkdownEngine.java From jbake with MIT License | 6 votes |
@Override public void processBody(final ParserContext context) { List<String> mdExts = context.getConfig().getMarkdownExtensions(); int extensions = PegdownExtensions.NONE; for (String ext : mdExts) { 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(); Document document = parser.parse(context.getBody()); context.setBody(renderer.render(document)); }
Example #2
Source File: MarkDownModel.java From Orienteer with Apache License 2.0 | 6 votes |
@Override protected String load() { String markDownValue = markDawnModel.getObject(); if (Strings.isEmpty(markDownValue)) { return ""; } try { MutableDataSet options = new MutableDataSet(); options.set(Parser.EXTENSIONS, createExtensions()); Parser parser = Parser.builder(options).build(); HtmlRenderer renderer = HtmlRenderer.builder(options).build(); Node node = parser.parse(markDawnModel.getObject()); markDownValue = renderer.render(node); } catch (Exception e) { throw new WicketRuntimeException("Can't use flexmark-java for markups", e); } return markDownValue; }
Example #3
Source File: MarkdownHandler.java From 1Rramp-Android with MIT License | 6 votes |
public static String getHtmlFromMarkdown(String md){ 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"); Parser parser = Parser.builder(options).build(); HtmlRenderer renderer = HtmlRenderer.builder(options).build(); Node document = parser.parse(md); String html = renderer.render(document); //do some more formatting html = RegexUtils.replaceMarkdownImage(html); html = RegexUtils.replacePlainImageLinks(html); return html; }
Example #4
Source File: MarkdownParser.java From OmniList with GNU Affero General Public License v3.0 | 6 votes |
@Override protected String doInBackground(String... strings) { Parser parser = Parser.builder(OPTIONS) .extensions(EXTENSIONS) .build(); HtmlRenderer renderer = HtmlRenderer.builder(OPTIONS) .escapeHtml(true) .attributeProviderFactory(new IndependentAttributeProviderFactory() { @Override public AttributeProvider create(NodeRendererContext context) { return new CustomAttributeProvider(); } }) .nodeRendererFactory(new NodeRendererFactoryImpl()) .extensions(EXTENSIONS) .build(); return renderer.render(parser.parse(strings[0])); }
Example #5
Source File: WikiFormatter.java From webdsl with Apache License 2.0 | 6 votes |
private static synchronized HtmlRenderer getHTMLRenderer( String rootUrl, boolean hardwrapsEnabled ){ if(!currentRootUrl.equals(rootUrl) && rootUrl != null ) { currentRootUrl = rootUrl; RENDERER_HW = null; RENDERER_NOHW = null; String linkPrefix = rootUrl + "/"; optionsHardWraps.set(WikiLinkExtension.LINK_PREFIX, linkPrefix); optionsNoHardWraps.set(WikiLinkExtension.LINK_PREFIX, linkPrefix); } if(hardwrapsEnabled){ if(RENDERER_HW == null){ RENDERER_HW = HtmlRenderer.builder( optionsHardWraps ).build(); } return RENDERER_HW; } else { if(RENDERER_NOHW == null){ RENDERER_NOHW = HtmlRenderer.builder( optionsNoHardWraps ).build(); } return RENDERER_NOHW; } }
Example #6
Source File: LinkRendererExtension.java From jphp with Apache License 2.0 | 6 votes |
@Override public void extend(HtmlRenderer.Builder rendererBuilder, String rendererType) { rendererBuilder.linkResolverFactory(new LinkResolverFactory() { @Override public Set<Class<? extends LinkResolverFactory>> getAfterDependents() { return null; } @Override public Set<Class<? extends LinkResolverFactory>> getBeforeDependents() { return null; } @Override public boolean affectsGlobalScope() { return false; } @Override public LinkResolver create(LinkResolverContext context) { return linkResolver; } }); }
Example #7
Source File: MarkdownEditerController.java From MyBox with Apache License 2.0 | 6 votes |
protected void makeConverter() { try { parserOptions = new MutableDataSet(); parserOptions.setFrom(ParserEmulationProfile.valueOf(emulationSelector.getValue())); parserOptions.set(Parser.EXTENSIONS, Arrays.asList( // AbbreviationExtension.create(), // DefinitionExtension.create(), // FootnoteExtension.create(), // TypographicExtension.create(), TablesExtension.create() )); parserOptions.set(HtmlRenderer.INDENT_SIZE, indentSize) // .set(HtmlRenderer.PERCENT_ENCODE_URLS, true) // .set(TablesExtension.COLUMN_SPANS, false) .set(TablesExtension.TRIM_CELL_WHITESPACE, trimCheck.isSelected()) .set(TablesExtension.APPEND_MISSING_COLUMNS, appendCheck.isSelected()) .set(TablesExtension.DISCARD_EXTRA_COLUMNS, discardCheck.isSelected()) .set(TablesExtension.APPEND_MISSING_COLUMNS, appendCheck.isSelected()); parser = Parser.builder(parserOptions).build(); renderer = HtmlRenderer.builder(parserOptions).build(); } catch (Exception e) { logger.error(e.toString()); } }
Example #8
Source File: MarkdownView.java From MarkdownView with Apache License 2.0 | 6 votes |
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)); }
Example #9
Source File: DocumentationGenerator.java From TestingApp with Apache License 2.0 | 6 votes |
public String getInstructionsAsHTML() { 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"); Parser parser = Parser.builder(options).build(); HtmlRenderer renderer = HtmlRenderer.builder(options).build(); String markdown = getInstructionsAsMarkdown(); // You can re-use parser and renderer instances Node document = parser.parse(markdown); return renderer.render(document); }
Example #10
Source File: MathJaxExtension.java From MarkdownView with Apache License 2.0 | 5 votes |
@Override public void extend(HtmlRenderer.Builder rendererBuilder, String rendererType) { switch (rendererType) { case "HTML": rendererBuilder.nodeRendererFactory(new NodeRendererFactory() { @Override public NodeRenderer create(DataHolder options) { return new MathJaxNodeRenderer(options); } }); break; } }
Example #11
Source File: LabelExtension.java From MarkdownView with Apache License 2.0 | 5 votes |
@Override public void extend(HtmlRenderer.Builder rendererBuilder, String rendererType) { switch (rendererType) { case "HTML": rendererBuilder.nodeRendererFactory(new LabelNodeRenderer.Factory()); break; } }
Example #12
Source File: BeanExtension.java From MarkdownView with Apache License 2.0 | 5 votes |
@Override public void extend(HtmlRenderer.Builder rendererBuilder, String rendererType) { switch (rendererType) { case "HTML": rendererBuilder.nodeRendererFactory(new BeanNodeRenderer.Factory()); break; } }
Example #13
Source File: DataRequirementsProvider.java From cqf-ruler with Apache License 2.0 | 5 votes |
private String markdownToHtml(Parser parser, HtmlRenderer renderer, String markdown) { if (Strings.isNullOrEmpty(markdown)) { return null; } Node document = parser.parse(markdown); return renderer.render(document); }
Example #14
Source File: FlexmarkParser.java From zeppelin with Apache License 2.0 | 5 votes |
public FlexmarkParser() { MutableDataSet options = new MutableDataSet(); options.set(Parser.EXTENSIONS, Arrays.asList(StrikethroughExtension.create(), TablesExtension.create(), UMLExtension.create(), AutolinkExtension.create(), WikiLinkExtension.create(), TypographicExtension.create())); options.set(HtmlRenderer.SOFT_BREAK, "<br />\n"); parser = Parser.builder(options).build(); renderer = HtmlRenderer.builder(options).build(); }
Example #15
Source File: WikiFormatter.java From webdsl with Apache License 2.0 | 5 votes |
public static String wikiFormat(String text, boolean useHardWraps, String rootUrl){ try { Node document = MARKDOWN_PARSER.parse( text ); HtmlRenderer renderer = getHTMLRenderer(rootUrl, useHardWraps); return renderer.render(document); // + "<!--end-->"; //This forces an unclosed HTML-comment in the rendered output to be closed. This fixes the issue where commonmark may escape a closing `-->` when a blank line exists in the HTML comment. // return processor.markdownToHtml( processVerbatim(text), getLinkRenderer( rootUrl ) ); } catch (Exception e) { Logger.error(e); return errorMessage(text); } }
Example #16
Source File: Utils.java From para with Apache License 2.0 | 5 votes |
private static MutableDataHolder getMarkdownOptions() { return new MutableDataSet() .set(HtmlRenderer.ESCAPE_HTML, true) .set(EmojiExtension.USE_IMAGE_TYPE, EmojiImageType.UNICODE_FALLBACK_TO_IMAGE) // 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())); }
Example #17
Source File: MarkdownDialog.java From gpx-animator with Apache License 2.0 | 5 votes |
private String convertMarkdownToHTML(final String md) { final MutableDataSet options = new MutableDataSet(); final Parser parser = Parser.builder(options).build(); final HtmlRenderer renderer = HtmlRenderer.builder(options).build(); final Node document = parser.parse(md); return renderer.render(document); }
Example #18
Source File: FileUtils.java From mogu_blog_v2 with Apache License 2.0 | 5 votes |
/** * Markdown转Html * @param markdown * @return */ public static String markdownToHtml(String markdown) { MutableDataSet options = new MutableDataSet(); Parser parser = Parser.builder(options).build(); HtmlRenderer renderer = HtmlRenderer.builder(options).build(); Node document = parser.parse(markdown); String html = renderer.render(document); return html; }
Example #19
Source File: HelpActivity.java From mhzs with MIT License | 5 votes |
/** * 展示网页 */ private void showHtml(String md) { DataHolder OPTIONS = PegdownOptionsAdapter.flexmarkOptions(true, Extensions.NONE); Parser parser = Parser.builder(OPTIONS).build(); HtmlRenderer renderer = HtmlRenderer.builder(OPTIONS).build(); Node document = parser.parse(md); String html = renderer.render(document); // LogUtil.e(html); mWebView.getSettings().setDefaultTextEncodingName("UTF-8"); mWebView.loadData(html, "text/html; charset=UTF-8", null); }
Example #20
Source File: KeystrokeExtension.java From MarkdownView with Apache License 2.0 | 5 votes |
@Override public void extend(HtmlRenderer.Builder rendererBuilder, String rendererType) { switch (rendererType) { case "HTML": rendererBuilder.nodeRendererFactory(new KeystrokeNodeRenderer.Factory()); break; } }
Example #21
Source File: Markdown2HtmlUtil.java From plumemo with Apache License 2.0 | 5 votes |
/** * Markdownz转为Html * @param content * @return */ public static String html(String content){ MutableDataSet options = new MutableDataSet(); options.setFrom(ParserEmulationProfile.MARKDOWN); options.set(Parser.EXTENSIONS, Arrays.asList(new Extension[]{TablesExtension.create()})); Parser parser = Parser.builder(options).build(); HtmlRenderer renderer = HtmlRenderer.builder(options).build(); Node document = parser.parse(content); return renderer.render(document); }
Example #22
Source File: MarkExtension.java From OmniList with GNU Affero General Public License v3.0 | 5 votes |
@Override public void extend(HtmlRenderer.Builder rendererBuilder, String rendererType) { switch (rendererType) { case "HTML": rendererBuilder.nodeRendererFactory(new NodeRendererFactory() { @Override public NodeRenderer create(DataHolder options) { return new MarkNodeRenderer(options); } }); break; } }
Example #23
Source File: MathJaxExtension.java From OmniList with GNU Affero General Public License v3.0 | 5 votes |
@Override public void extend(HtmlRenderer.Builder rendererBuilder, String rendererType) { switch (rendererType) { case "HTML": rendererBuilder.nodeRendererFactory(new NodeRendererFactory() { @Override public NodeRenderer create(DataHolder options) { return new MathJaxNodeRenderer(options); } }); break; } }
Example #24
Source File: MarkdownToHtmlController.java From MyBox with Apache License 2.0 | 5 votes |
@Override public boolean makeMoreParameters() { try { parserOptions = new MutableDataSet(); parserOptions.setFrom(ParserEmulationProfile.valueOf(emulationSelector.getValue())); parserOptions.set(Parser.EXTENSIONS, Arrays.asList( // AbbreviationExtension.create(), // DefinitionExtension.create(), // FootnoteExtension.create(), // TypographicExtension.create(), TablesExtension.create() )); parserOptions.set(HtmlRenderer.INDENT_SIZE, indentSize) // .set(HtmlRenderer.PERCENT_ENCODE_URLS, true) // .set(TablesExtension.COLUMN_SPANS, false) .set(TablesExtension.TRIM_CELL_WHITESPACE, trimCheck.isSelected()) .set(TablesExtension.APPEND_MISSING_COLUMNS, appendCheck.isSelected()) .set(TablesExtension.DISCARD_EXTRA_COLUMNS, discardCheck.isSelected()) .set(TablesExtension.APPEND_MISSING_COLUMNS, appendCheck.isSelected()); parser = Parser.builder(parserOptions).build(); renderer = HtmlRenderer.builder(parserOptions).build(); } catch (Exception e) { logger.error(e.toString()); return false; } return super.makeMoreParameters(); }
Example #25
Source File: MarkDownUtil.java From smart-doc with Apache License 2.0 | 5 votes |
/** * Convert markdown to html. * * @param content markdown contents * @return html contents */ public static String toHtml(String content) { MutableDataSet options = new MutableDataSet(); options.setFrom(ParserEmulationProfile.MARKDOWN); // enable table parse! options.set(Parser.EXTENSIONS, Arrays.asList(TablesExtension.create(), StrikethroughExtension.create())); Parser parser = Parser.builder(options).build(); HtmlRenderer renderer = HtmlRenderer.builder(options).build(); Node document = parser.parse(content); return renderer.render(document); }
Example #26
Source File: MarkExtension.java From MarkdownView with Apache License 2.0 | 5 votes |
@Override public void extend(HtmlRenderer.Builder rendererBuilder, String rendererType) { switch (rendererType) { case "HTML": rendererBuilder.nodeRendererFactory(new NodeRendererFactory() { @Override public NodeRenderer create(DataHolder options) { return new MarkNodeRenderer(options); } }); break; } }
Example #27
Source File: DefaultMarkdownManager.java From onedev with MIT License | 5 votes |
@Override public String render(String markdown) { 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.addAll(contributedExtensions); MutableDataHolder options = new MutableDataSet() .set(HtmlRenderer.GENERATE_HEADER_ID, true) .set(AnchorLinkExtension.ANCHORLINKS_SET_NAME, true) .set(AnchorLinkExtension.ANCHORLINKS_WRAP_TEXT, false) .set(AnchorLinkExtension.ANCHORLINKS_TEXT_PREFIX, "<span class='header-anchor'></span>") .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(Parser.EXTENSIONS, extensions); Parser parser = Parser.builder(options).build(); HtmlRenderer htmlRenderer = HtmlRenderer.builder(options).build(); Node document = parser.parse(markdown); return htmlRenderer.render(document); }
Example #28
Source File: PageGeneratorExtension.java From markdown-page-generator-plugin with MIT License | 4 votes |
@Override public void extend(HtmlRenderer.Builder rendererBuilder, String rendererType) { rendererBuilder.linkResolverFactory(new FlexmarkLinkResolver.Factory()); }
Example #29
Source File: AttributesExtension.java From markdown-page-generator-plugin with MIT License | 4 votes |
@Override public void extend(HtmlRenderer.Builder rendererBuilder, String rendererType) { rendererBuilder.attributeProviderFactory(new FlexmarkAttributeProvider.Factory()); }
Example #30
Source File: PMarkdownOptions.java From jphp with Apache License 2.0 | 4 votes |
@Signature public PMarkdownOptions setRenderSuppressHtml(boolean value) { options.set(HtmlRenderer.SUPPRESS_HTML, value); return this; }