本文整理汇总了Java中org.commonmark.node.Node类的典型用法代码示例。如果您正苦于以下问题:Java Node类的具体用法?Java Node怎么用?Java Node使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Node类属于org.commonmark.node包,在下文中一共展示了Node类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: render
import org.commonmark.node.Node; //导入依赖的package包/类
public String render(String text, String format) {
if (text == null || text.length() == 0) {
return text;
}
try {
Parser parser = Parser.builder().build();
Node document = parser.parse(text);
Renderer renderer;
if (format.equals("html")) {
renderer = HtmlRenderer.builder().build();
} else {
renderer = TextContentRenderer.builder().build();
}
return renderer.render(document);
} catch (Exception e) {
logger.error("A problem occurred while rendering an email: {}", e);
return text;
}
}
示例2: render
import org.commonmark.node.Node; //导入依赖的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())));
}
}
示例3: generateContents
import org.commonmark.node.Node; //导入依赖的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);
}
示例4: MockBodyPost
import org.commonmark.node.Node; //导入依赖的package包/类
public MockBodyPost(String bodyMarkdown) {
super("","",null,null,
1, 1, "", bodyMarkdown, null, null, null, "", "");
SOUser asker = new SOUser("testUser",-1,1,"registered");
SOUser answerer = new SOUser("testUser",-1,1,"unregistered");
setAnswerCreationDate(Instant.now());
setQuestionCreationDate(Instant.EPOCH);
setAsker(asker);
setAnswerer(answerer);
Parser parser = Parser.builder().build();
Node document = parser.parse(bodyMarkdown);
HtmlRenderer renderer = HtmlRenderer.builder().build();
setBody(renderer.render(document));
}
示例5: simpleValue
import org.commonmark.node.Node; //导入依赖的package包/类
@Test
public void simpleValue() {
final String input = "---" +
"\nhello: world" +
"\n..." +
"\n" +
"\ngreat";
final String rendered = "<p>great</p>\n";
YamlFrontMatterVisitor visitor = new YamlFrontMatterVisitor();
Node document = PARSER.parse(input);
document.accept(visitor);
Map<String, List<String>> data = visitor.getData();
assertEquals(1, data.size());
assertEquals("hello", data.keySet().iterator().next());
assertEquals(1, data.get("hello").size());
assertEquals("world", data.get("hello").get(0));
assertRendering(input, rendered);
}
示例6: emptyValue
import org.commonmark.node.Node; //导入依赖的package包/类
@Test
public void emptyValue() {
final String input = "---" +
"\nkey:" +
"\n---" +
"\n" +
"\ngreat";
final String rendered = "<p>great</p>\n";
YamlFrontMatterVisitor visitor = new YamlFrontMatterVisitor();
Node document = PARSER.parse(input);
document.accept(visitor);
Map<String, List<String>> data = visitor.getData();
assertEquals(1, data.size());
assertEquals("key", data.keySet().iterator().next());
assertEquals(0, data.get("key").size());
assertRendering(input, rendered);
}
示例7: listValues
import org.commonmark.node.Node; //导入依赖的package包/类
@Test
public void listValues() {
final String input = "---" +
"\nlist:" +
"\n - value1" +
"\n - value2" +
"\n..." +
"\n" +
"\ngreat";
final String rendered = "<p>great</p>\n";
YamlFrontMatterVisitor visitor = new YamlFrontMatterVisitor();
Node document = PARSER.parse(input);
document.accept(visitor);
Map<String, List<String>> data = visitor.getData();
assertEquals(1, data.size());
assertTrue(data.containsKey("list"));
assertEquals(2, data.get("list").size());
assertEquals("value1", data.get("list").get(0));
assertEquals("value2", data.get("list").get(1));
assertRendering(input, rendered);
}
示例8: literalValue1
import org.commonmark.node.Node; //导入依赖的package包/类
@Test
public void literalValue1() {
final String input = "---" +
"\nliteral: |" +
"\n hello markdown!" +
"\n literal thing..." +
"\n---" +
"\n" +
"\ngreat";
final String rendered = "<p>great</p>\n";
YamlFrontMatterVisitor visitor = new YamlFrontMatterVisitor();
Node document = PARSER.parse(input);
document.accept(visitor);
Map<String, List<String>> data = visitor.getData();
assertEquals(1, data.size());
assertTrue(data.containsKey("literal"));
assertEquals(1, data.get("literal").size());
assertEquals("hello markdown!\nliteral thing...", data.get("literal").get(0));
assertRendering(input, rendered);
}
示例9: literalValue2
import org.commonmark.node.Node; //导入依赖的package包/类
@Test
public void literalValue2() {
final String input = "---" +
"\nliteral: |" +
"\n - hello markdown!" +
"\n---" +
"\n" +
"\ngreat";
final String rendered = "<p>great</p>\n";
YamlFrontMatterVisitor visitor = new YamlFrontMatterVisitor();
Node document = PARSER.parse(input);
document.accept(visitor);
Map<String, List<String>> data = visitor.getData();
assertEquals(1, data.size());
assertTrue(data.containsKey("literal"));
assertEquals(1, data.get("literal").size());
assertEquals("- hello markdown!", data.get("literal").get(0));
assertRendering(input, rendered);
}
示例10: empty
import org.commonmark.node.Node; //导入依赖的package包/类
@Test
public void empty() {
final String input = "---\n" +
"---\n" +
"test";
final String rendered = "<p>test</p>\n";
YamlFrontMatterVisitor visitor = new YamlFrontMatterVisitor();
Node document = PARSER.parse(input);
document.accept(visitor);
Map<String, List<String>> data = visitor.getData();
assertTrue(data.isEmpty());
assertRendering(input, rendered);
}
示例11: yamlInParagraph
import org.commonmark.node.Node; //导入依赖的package包/类
@Test
public void yamlInParagraph() {
final String input = "# hello\n" +
"\nhello markdown world!" +
"\n---" +
"\nhello: world" +
"\n---";
final String rendered = "<h1>hello</h1>\n<h2>hello markdown world!</h2>\n<h2>hello: world</h2>\n";
YamlFrontMatterVisitor visitor = new YamlFrontMatterVisitor();
Node document = PARSER.parse(input);
document.accept(visitor);
Map<String, List<String>> data = visitor.getData();
assertTrue(data.isEmpty());
assertRendering(input, rendered);
}
示例12: yamlOnSecondLine
import org.commonmark.node.Node; //导入依赖的package包/类
@Test
public void yamlOnSecondLine() {
final String input = "hello\n" +
"\n---" +
"\nhello: world" +
"\n---";
final String rendered = "<p>hello</p>\n<hr />\n<h2>hello: world</h2>\n";
YamlFrontMatterVisitor visitor = new YamlFrontMatterVisitor();
Node document = PARSER.parse(input);
document.accept(visitor);
Map<String, List<String>> data = visitor.getData();
assertTrue(data.isEmpty());
assertRendering(input, rendered);
}
示例13: nonMatchedStartTag
import org.commonmark.node.Node; //导入依赖的package包/类
@Test
public void nonMatchedStartTag() {
final String input = "----\n" +
"test";
final String rendered = "<hr />\n<p>test</p>\n";
YamlFrontMatterVisitor visitor = new YamlFrontMatterVisitor();
Node document = PARSER.parse(input);
document.accept(visitor);
Map<String, List<String>> data = visitor.getData();
assertTrue(data.isEmpty());
assertRendering(input, rendered);
}
示例14: inList
import org.commonmark.node.Node; //导入依赖的package包/类
@Test
public void inList() {
final String input = "* ---\n" +
" ---\n" +
"test";
final String rendered = "<ul>\n<li>\n<hr />\n<hr />\n</li>\n</ul>\n<p>test</p>\n";
YamlFrontMatterVisitor visitor = new YamlFrontMatterVisitor();
Node document = PARSER.parse(input);
document.accept(visitor);
Map<String, List<String>> data = visitor.getData();
assertTrue(data.isEmpty());
assertRendering(input, rendered);
}
示例15: visitorIgnoresOtherCustomNodes
import org.commonmark.node.Node; //导入依赖的package包/类
@Test
public void visitorIgnoresOtherCustomNodes() {
final String input = "---" +
"\nhello: world" +
"\n---" +
"\n";
YamlFrontMatterVisitor visitor = new YamlFrontMatterVisitor();
Node document = PARSER.parse(input);
document.appendChild(new TestNode());
document.accept(visitor);
Map<String, List<String>> data = visitor.getData();
assertEquals(1, data.size());
assertTrue(data.containsKey("hello"));
assertEquals(Collections.singletonList("world"), data.get("hello"));
}