本文整理汇总了Java中org.commonmark.node.Node.accept方法的典型用法代码示例。如果您正苦于以下问题:Java Node.accept方法的具体用法?Java Node.accept怎么用?Java Node.accept使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.commonmark.node.Node
的用法示例。
在下文中一共展示了Node.accept方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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);
}
示例3: 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);
}
示例4: 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);
}
示例5: 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);
}
示例6: 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);
}
示例7: 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);
}
示例8: 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);
}
示例9: 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);
}
示例10: 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);
}
示例11: 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"));
}
示例12: nodesCanBeModified
import org.commonmark.node.Node; //导入方法依赖的package包/类
@Test
public void nodesCanBeModified() {
final String input = "---" +
"\nhello: world" +
"\n---" +
"\n";
Node document = PARSER.parse(input);
YamlFrontMatterNode node = (YamlFrontMatterNode) document.getFirstChild().getFirstChild();
node.setKey("see");
node.setValues(Collections.singletonList("you"));
YamlFrontMatterVisitor visitor = new YamlFrontMatterVisitor();
document.accept(visitor);
Map<String, List<String>> data = visitor.getData();
assertEquals(1, data.size());
assertTrue(data.containsKey("see"));
assertEquals(Collections.singletonList("you"), data.get("see"));
}
示例13: findSequences
import org.commonmark.node.Node; //导入方法依赖的package包/类
@Override
public List<Range> findSequences(int startOffset, int endOffset) {
ArrayList<Range> sequences = new ArrayList<>();
Node astRoot = toAstRoot();
if (astRoot == null)
return sequences;
Visitor visitor = new AbstractVisitor() {
@Override
protected void visitChildren(Node node) {
Range range = toSourcePositions().get(node);
if (range != null && isInRange(startOffset, endOffset, range))
sequences.add(range);
super.visitChildren(node);
}
};
astRoot.accept(visitor);
return sequences;
}
示例14: setAttributes
import org.commonmark.node.Node; //导入方法依赖的package包/类
@Override
public void setAttributes(Node node, Map<String, String> attributes) {
if (node instanceof Heading) {
MarkdownTextVisitor textVisitor = new MarkdownTextVisitor();
node.accept(textVisitor);
String label = textVisitor.getText();
Integer level = ((Heading) node).getLevel();
String id = label.replaceAll("\\W", "-").replaceAll("-+", "-").toLowerCase();
if (usedIds.contains(id)) {
// Find an unused ID by appending numbers
int uniqueIdSuffix = 1;
while (usedIds.contains(id + "-" + uniqueIdSuffix)) {
uniqueIdSuffix++;
}
id = id + "-" + uniqueIdSuffix;
}
usedIds.add(id);
TocEntry tocEntry = new TocEntry(label, level, id);
toc.add(tocEntry);
attributes.put("id", tocEntry.getAnchorId());
}
}
示例15: test
import org.commonmark.node.Node; //导入方法依赖的package包/类
@Test
public void test() {
String testInputDocument = "Foo\n"
+ "# Generated Section - Pages\n"
+ "Bar\n"
+ "## Generated Section - Categories\n";
String testOutputDocument = "Foo\n"
+ "# Pages\n"
+ "* [Foo](foo.md)\n"
+ "* [Bar](bar.md)\n"
+ "\nBar\n"
+ "## Categories\n"
+ "* [Goo](goo/index.md)\n"
+ "* [Gar](gar/index.md)\n";
Node testDocument = Parser.builder().build().parse(testInputDocument);
Node expectedDocument = Parser.builder().build().parse(testOutputDocument);
List<String> siblingPages = Arrays.asList(new String[]{"foo.md", "bar.md"});
List<String> subCategories = Arrays.asList(new String[]{"goo", "gar"});
NavigationLinkInjector navigationLinkInjector = new NavigationLinkInjector(
Paths.get("/example/example.md"), Paths.get("/example"),
siblingPages, subCategories);
testDocument.accept(navigationLinkInjector);
HtmlRenderer renderer = HtmlRenderer.builder().build();
Assert.assertEquals(renderer.render(expectedDocument), renderer.render(testDocument));
}