本文整理汇总了Java中org.commonmark.ext.gfm.tables.TablesExtension类的典型用法代码示例。如果您正苦于以下问题:Java TablesExtension类的具体用法?Java TablesExtension怎么用?Java TablesExtension使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TablesExtension类属于org.commonmark.ext.gfm.tables包,在下文中一共展示了TablesExtension类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: render
import org.commonmark.ext.gfm.tables.TablesExtension; //导入依赖的package包/类
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())));
}
}
示例2: generateContents
import org.commonmark.ext.gfm.tables.TablesExtension; //导入依赖的package包/类
public String generateContents(Page page) throws IOException {
List<Extension> extensions = Collections.singletonList(TablesExtension.create());
Parser parser = Parser
.builder()
.extensions(extensions)
.build();
HtmlRenderer renderer = HtmlRenderer
.builder()
.attributeProvider((node, attributes) -> {
if (node instanceof TableBlock) {
attributes.put("class", "table");
}
})
.extensions(extensions)
.build();
Node document = parser.parseReader(new FileReader(page.getFile()));
return renderer.render(document);
}
示例3: mdToHtml
import org.commonmark.ext.gfm.tables.TablesExtension; //导入依赖的package包/类
/**
* 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;
}
示例4: createParser
import org.commonmark.ext.gfm.tables.TablesExtension; //导入依赖的package包/类
/**
* Helper method to obtain a Parser with registered strike-through & table extensions
* & task lists (added in 1.0.1)
*
* @return a Parser instance that is supported by this library
* @since 1.0.0
*/
@NonNull
public static Parser createParser() {
return new Parser.Builder()
.extensions(Arrays.asList(
StrikethroughExtension.create(),
TablesExtension.create(),
TaskListExtension.create()
))
.build();
}
示例5: markdownToHTML
import org.commonmark.ext.gfm.tables.TablesExtension; //导入依赖的package包/类
private String markdownToHTML(String md) {
List<Extension> extensions = Arrays.asList(TablesExtension.create());
final Parser parser = Parser.builder().extensions(extensions).build();
final Node doc = parser.parse(md);
final HtmlRenderer renderer = HtmlRenderer.builder().extensions(extensions).build();
return renderer.render(doc);
}
示例6: CommonMarkUtils
import org.commonmark.ext.gfm.tables.TablesExtension; //导入依赖的package包/类
public CommonMarkUtils () {
List<Extension> extensions = Arrays.asList(TablesExtension.create(), StrikethroughExtension.create(), HeadingAnchorExtension.create(), InsExtension.create());
parser = Parser.builder().extensions(extensions).build();
renderer = HtmlRenderer.builder().extensions(extensions).build();
}
示例7: process
import org.commonmark.ext.gfm.tables.TablesExtension; //导入依赖的package包/类
public MarkdownProcessorResult process(String markdownContent, List<Visitor> visitors) {
List<Extension> extensions = Arrays.asList(TablesExtension.create(), YamlFrontMatterExtension.create());
Parser parser = Parser.builder().extensions(extensions).build();
Node document = parser.parse(markdownContent);
YamlFrontMatterVisitor yamlVisitor = new YamlFrontMatterVisitor();
document.accept(yamlVisitor);
Set<String> linkTargets = new HashSet<>();
// Modify listing headings
for (Visitor visitor : visitors) {
document.accept(visitor); // new NavigationLinkInjector(siblingPages, subCategories));
}
// Fix links to *.md to go to *.html instead
document.accept(new AbstractVisitor() {
@Override
public void visit(Link link) {
URI uri = URI.create(link.getDestination());
linkTargets.add(link.getDestination());
link.setDestination(MarkdownUtils.renameFilenameForMarkdownPage(link.getDestination()));
visitChildren(link);
}
});
MarkdownTocGenerator tocGenerator = new MarkdownTocGenerator();
HtmlRenderer renderer = HtmlRenderer.builder().extensions(extensions).attributeProviderFactory(new AttributeProviderFactory() {
@Override
public AttributeProvider create(AttributeProviderContext context) {
return tocGenerator;
}
}).build();
String renderedContent = renderer.render(document);
MarkdownProcessorResult result = new MarkdownProcessorResult(renderedContent, tocGenerator.getToc(), yamlVisitor.getData());
result.getLinkTargets().addAll(linkTargets);
return result;
}
示例8: tablesExtensionTest
import org.commonmark.ext.gfm.tables.TablesExtension; //导入依赖的package包/类
@Test
public void tablesExtensionTest() throws Exception {
parseWithExtensionsTest(TablesExtension.create());
}