如何让 Flexmark-Java 处理“@”-mentions?
How to make Flexmark-Java process "@"-mentions?
在处理 markdown 时,GitHub 支持 @
-syntax 到 mention a username or team。如何使用 Flexmark-Java 处理此类提及?使用以下代码片段,Hello, @world !
被报告为单个 Text
节点,我希望将 world
单独报告为某种 MentionsNode:
final Parser parser = Parser.builder(new Parser.Builder()).build();
final Document document = parser.parse("Hello, @world !");
new NodeVisitor(Collections.emptyList()) {
public void visit(Node node) {
System.out.println("Node: " + node);
super.visit(node);
}
}.visit(document);
输出:
Node: Document{}
Node: Paragraph{}
Node: Text{text=Hello, @world !}
这个有相应的扩展:
final MutableDataHolder options = new MutableDataSet()
.set(Parser.EXTENSIONS, Collections.singletonList(GfmUsersExtension.create()));
final Parser parser = Parser.builder(options).build();
final Document document = parser.parse("Hello, @world, and #1!");
...
在处理 markdown 时,GitHub 支持 @
-syntax 到 mention a username or team。如何使用 Flexmark-Java 处理此类提及?使用以下代码片段,Hello, @world !
被报告为单个 Text
节点,我希望将 world
单独报告为某种 MentionsNode:
final Parser parser = Parser.builder(new Parser.Builder()).build();
final Document document = parser.parse("Hello, @world !");
new NodeVisitor(Collections.emptyList()) {
public void visit(Node node) {
System.out.println("Node: " + node);
super.visit(node);
}
}.visit(document);
输出:
Node: Document{}
Node: Paragraph{}
Node: Text{text=Hello, @world !}
这个有相应的扩展:
final MutableDataHolder options = new MutableDataSet()
.set(Parser.EXTENSIONS, Collections.singletonList(GfmUsersExtension.create()));
final Parser parser = Parser.builder(options).build();
final Document document = parser.parse("Hello, @world, and #1!");
...