org.commonmark.ext.gfm.tables.TablesExtension Java Examples
The following examples show how to use
org.commonmark.ext.gfm.tables.TablesExtension.
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: MarkdownUtil.java From Roothub with GNU Affero General Public License v3.0 | 7 votes |
/** * 渲染 Markdown * @param content * @return */ public static String render(String content) { List<Extension> extensions = Arrays.asList( AutolinkExtension.create(), TablesExtension.create()); Parser parser = Parser.builder() .extensions(extensions) .build(); // 回车一次就可以实现换行 HtmlRenderer renderer = HtmlRenderer.builder() .softbreak("<br/>") .attributeProviderFactory(context -> new MyAttributeProvider()) .extensions(extensions) .build(); Node document = parser.parse(content == null ? "" : content); return renderer.render(document); }
Example #2
Source File: MarkDownProvider.java From mvvm-template with GNU General Public License v3.0 | 6 votes |
protected static void render(@NonNull TextView textView, String markdown, int width) { List<Extension> extensions = Arrays.asList( StrikethroughExtension.create(), AutolinkExtension.create(), TablesExtension.create(), InsExtension.create(), EmojiExtension.create(), MentionExtension.create(), YamlFrontMatterExtension.create()); Parser parser = Parser.builder() .extensions(extensions) .build(); try { Node node = parser.parse(markdown); String rendered = HtmlRenderer .builder() .extensions(extensions) .build() .render(node); HtmlHelper.htmlIntoTextView(textView, rendered, (width - (textView.getPaddingStart() + textView.getPaddingEnd()))); } catch (Exception ignored) { HtmlHelper.htmlIntoTextView(textView, markdown, (width - (textView.getPaddingStart() + textView.getPaddingEnd()))); } }
Example #3
Source File: TaleUtils.java From tale with MIT License | 6 votes |
/** * markdown转换为html * * @param markdown * @return */ public static String mdToHtml(String markdown) { if (StringKit.isBlank(markdown)) { return ""; } List<Extension> extensions = Arrays.asList(TablesExtension.create()); Parser parser = Parser.builder().extensions(extensions).build(); Node document = parser.parse(markdown); HtmlRenderer renderer = HtmlRenderer.builder().extensions(extensions).build(); String content = renderer.render(document); content = Commons.emoji(content); // 支持网易云音乐输出 if (TaleConst.BCONF.getBoolean("app.support_163_music", true) && content.contains("[mp3:")) { content = content.replaceAll("\\[mp3:(\\d+)\\]", "<iframe frameborder=\"no\" border=\"0\" marginwidth=\"0\" marginheight=\"0\" width=350 height=106 src=\"//music.163.com/outchain/player?type=2&id=$1&auto=0&height=88\"></iframe>"); } // 支持gist代码输出 if (TaleConst.BCONF.getBoolean("app.support_gist", true) && content.contains("https://gist.github.com/")) { content = content.replaceAll("<script src=\"https://gist.github.com/(\\w+)/(\\w+)\\.js\"></script>", "<script src=\"https://gist.github.com/$1/$2\\.js\"></script>"); } return content; }
Example #4
Source File: MarkdownController.java From java-docs-samples with Apache License 2.0 | 6 votes |
@PostMapping("/") public String markdownRenderer(@RequestBody String payload) { // Set up HTML renderer // https://github.com/atlassian/commonmark-java#extensions List<Extension> extensions = Arrays.asList(TablesExtension.create(), StrikethroughExtension.create()); Parser parser = Parser.builder().extensions(extensions).build(); Node document = parser.parse(payload); HtmlRenderer renderer = HtmlRenderer.builder().extensions(extensions).build(); // Convert Markdown to HTML String converted = renderer.render(document); // Use prepackaged policies to sanitize HTML. Cusomized and tighter standards // are recommended. PolicyFactory policy = Sanitizers.FORMATTING .and(Sanitizers.BLOCKS) .and(Sanitizers.LINKS) .and(Sanitizers.IMAGES) .and(Sanitizers.TABLES); String safeHtml = policy.sanitize(converted); return safeHtml; }
Example #5
Source File: MarkDownUtil.java From My-Blog with Apache License 2.0 | 5 votes |
/** * 转换md格式为html * * @param markdownString * @return */ public static String mdToHtml(String markdownString) { if (StringUtils.isEmpty(markdownString)) { return ""; } java.util.List<Extension> extensions = Arrays.asList(TablesExtension.create()); Parser parser = Parser.builder().extensions(extensions).build(); Node document = parser.parse(markdownString); HtmlRenderer renderer = HtmlRenderer.builder().extensions(extensions).build(); String content = renderer.render(document); return content; }
Example #6
Source File: MarkDownProcessor.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private String processCommonMark(String source) { Set<Extension> extensions = Collections.singleton(TablesExtension.create()); Parser parser = Parser.builder().extensions(extensions).build(); Node document = parser.parse(source); HtmlRenderer renderer = HtmlRenderer.builder().extensions(extensions).build(); String html = renderer.render(document); html = html.replace("<table>", "<table class=\"grid\">"); return html; }
Example #7
Source File: MarkDownUtils.java From My-Blog-layui with Apache License 2.0 | 5 votes |
/** * 转换md格式为html * * @param markdownString * @return */ public static String mdToHtml(String markdownString) { if (StringUtils.isEmpty(markdownString)) { return ""; } List<Extension> extensions = Arrays.asList(TablesExtension.create()); Parser parser = Parser.builder().extensions(extensions).build(); Node document = parser.parse(markdownString); HtmlRenderer renderer = HtmlRenderer.builder().extensions(extensions).build(); return renderer.render(document); }
Example #8
Source File: TaleUtils.java From my-site with Apache License 2.0 | 5 votes |
/** * markdown转换为html * * @param markdown * @return */ public static String mdToHtml(String markdown) { if (StringUtils.isBlank(markdown)) { return ""; } java.util.List<Extension> extensions = Arrays.asList(TablesExtension.create()); Parser parser = Parser.builder().extensions(extensions).build(); Node document = parser.parse(markdown); HtmlRenderer renderer = HtmlRenderer.builder().extensions(extensions).build(); String content = renderer.render(document); content = Commons.emoji(content); return content; }
Example #9
Source File: MyUtils.java From Jantent with MIT License | 5 votes |
/** * markdown转换为html * * @param markdown * @return */ public static String mdToHtml(String markdown) { if (StringUtils.isBlank(markdown)) { return ""; } List<Extension> extensions = Arrays.asList(TablesExtension.create()); Parser parser = Parser.builder().extensions(extensions).build(); Node document = parser.parse(markdown); HtmlRenderer renderer = HtmlRenderer.builder() .attributeProviderFactory(context -> new LinkAttributeProvider()) .extensions(extensions).build(); String content = renderer.render(document); content = Commons.emoji(content); return content; }
Example #10
Source File: MarkdownUtil.java From pybbs with GNU Affero General Public License v3.0 | 5 votes |
public static String render(String content) { List<Extension> extensions = Arrays.asList(AutolinkExtension.create(), TablesExtension.create()); Parser parser = Parser.builder().extensions(extensions).build(); // 回车一次就可以实现换行 HtmlRenderer renderer = HtmlRenderer.builder().softbreak("<br/>").attributeProviderFactory(context -> new MyAttributeProvider()).extensions(extensions).build(); Node document = parser.parse(content == null ? "" : content); return renderer.render(document); }
Example #11
Source File: RenderMarkdown.java From symja_android_library with GNU General Public License v3.0 | 5 votes |
public static void main(String[] args) { Set<Extension> EXTENSIONS = Collections.singleton(TablesExtension.create()); Parser parser = Parser.builder().extensions(EXTENSIONS).build(); Node document = parser.parse(TABLE); HtmlRenderer renderer = HtmlRenderer.builder().extensions(EXTENSIONS).build(); String html = renderer.render(document); System.out.println(html); }
Example #12
Source File: DocumentationPod.java From symja_android_library with GNU General Public License v3.0 | 5 votes |
private static String generateHTMLString(final String markdownStr) { Set<Extension> EXTENSIONS = Collections.singleton(TablesExtension.create()); Parser parser = Parser.builder().extensions(EXTENSIONS).build(); Node document = parser.parse(markdownStr); HtmlRenderer renderer = HtmlRenderer.builder().extensions(EXTENSIONS).build(); return renderer.render(document); }
Example #13
Source File: TableEntryPlugin.java From Markwon with Apache License 2.0 | 4 votes |
@Override public void configureParser(@NonNull Parser.Builder builder) { builder.extensions(Collections.singleton(TablesExtension.create())); }
Example #14
Source File: TablePlugin.java From Markwon with Apache License 2.0 | 4 votes |
@Override public void configureParser(@NonNull Parser.Builder builder) { builder.extensions(Collections.singleton(TablesExtension.create())); }
Example #15
Source File: AndroidSupportTest.java From commonmark-java with BSD 2-Clause "Simplified" License | 4 votes |
@Test public void tablesExtensionTest() throws Exception { parseWithExtensionsTest(TablesExtension.create()); }
Example #16
Source File: MarkdownToHTML.java From symja_android_library with GNU General Public License v3.0 | 4 votes |
/** * Generate markdown links for Symja function reference. * * @param sourceLocation * source directory for funtions (*.md) files */ public static void generateHTMLString(final File sourceLocation, String function, boolean javadoc) { if (sourceLocation.exists()) { // Get the list of the files contained in the package final String[] files = sourceLocation.list(); if (files != null) { for (int i = 0; i < files.length; i++) { if (files[i].endsWith(".md")) { String className = files[i].substring(0, files[i].length() - 3); if (className.equals(function)) { File file = new File(sourceLocation + "/" + files[i]); String html; try { Set<Extension> EXTENSIONS = Collections.singleton(TablesExtension.create()); Parser parser = Parser.builder().extensions(EXTENSIONS).build(); Node document = parser.parse(Files.asCharSource(file, Charsets.UTF_8).read()); HtmlRenderer renderer = HtmlRenderer.builder().extensions(EXTENSIONS).build(); html = renderer.render(document); if (javadoc) { String[] lines = html.split("\\n"); System.out.println("/**"); for (int j = 0; j < lines.length; j++) { if (!lines[j].startsWith("<h2>")) { System.out.println(" * " + lines[j]); } } System.out.println(" */"); } else { System.out.println(html); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } } } }