use of com.vladsch.flexmark.ast.Node in project flexmark-java by vsch.
the class YamlFrontMatterTest method complexValues.
@Test
public void complexValues() {
final String input = "---" + "\nsimple: value" + "\nliteral: |" + "\n hello markdown!" + "\n" + "\n literal literal" + "\nlist:" + "\n - value1" + "\n - value2" + "\n---" + "\ngreat";
final String rendered = "<p>great</p>\n";
AbstractYamlFrontMatterVisitor visitor = new AbstractYamlFrontMatterVisitor();
Node document = PARSER.parse(input);
visitor.visit(document);
Map<String, List<String>> data = visitor.getData();
assertEquals(3, data.size());
assertTrue(data.containsKey("simple"));
assertEquals(1, data.get("simple").size());
assertEquals("value", data.get("simple").get(0));
assertTrue(data.containsKey("literal"));
assertEquals(1, data.get("literal").size());
assertEquals("hello markdown!\n\nliteral literal", data.get("literal").get(0));
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);
}
use of com.vladsch.flexmark.ast.Node in project flexmark-java by vsch.
the class YamlFrontMatterTest method literalValue1.
@Test
public void literalValue1() {
final String input = "---" + "\nliteral: |" + "\n hello markdown!" + "\n literal thing..." + "\n---" + "\n" + "\ngreat";
final String rendered = "<p>great</p>\n";
AbstractYamlFrontMatterVisitor visitor = new AbstractYamlFrontMatterVisitor();
Node document = PARSER.parse(input);
visitor.visit(document);
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);
}
use of com.vladsch.flexmark.ast.Node in project flexmark-java by vsch.
the class YouTubeLinkNodePostProcessor method process.
@Override
public void process(NodeTracker state, Node node) {
if (node instanceof Link) {
Node previous = node.getPrevious();
if (previous instanceof Text) {
final BasedSequence chars = previous.getChars();
if (chars.endsWith("@") && chars.isContinuedBy(node.getChars())) {
// trim previous chars to remove '@'
previous.setChars(chars.subSequence(0, chars.length() - 1));
YouTubeLink youTubeLink = new YouTubeLink((Link) node);
youTubeLink.takeChildren(node);
node.unlink();
previous.insertAfter(youTubeLink);
state.nodeRemoved(node);
state.nodeAddedWithChildren(youTubeLink);
}
}
}
}
use of com.vladsch.flexmark.ast.Node in project flexmark-java by vsch.
the class MacroBlockParser method closeBlock.
@Override
public void closeBlock(ParserState state) {
// first line is macro open and possibly close
if (oneLine) {
List<BasedSequence> lines = new ArrayList<BasedSequence>();
Macro macro = (Macro) block.getFirstChild();
Node node = block.getLastChild();
BasedSequence contentLine;
if (node instanceof MacroClose) {
contentLine = macro.getChars().baseSubSequence(macro.getEndOffset(), node.getStartOffset());
} else {
contentLine = macro.getChars().baseSubSequence(macro.getEndOffset(), macro.getEndOffset());
}
lines.add(contentLine);
block.setContent(lines);
} else {
// last line is close, first line is open
if (hadClose) {
final List<BasedSequence> lines = content.getLines();
block.setContent(lines);
} else {
final List<BasedSequence> lines = content.getLines();
block.setContent(lines.subList(0, lines.size()));
}
}
block.setCharsFromContent();
content = null;
}
use of com.vladsch.flexmark.ast.Node in project flexmark-java by vsch.
the class MarkdownWriter method tailBlankLine.
public MarkdownWriter tailBlankLine(int count) {
Node node = context.getCurrentNode();
if (isLastBlockQuoteChild(node)) {
if (getPushedPrefixCount() > 0) {
// clear pending lines so pop prefix is not delayed, if PREFIX_AFTER_PENDING_EOL is enabled
flush(-1);
popPrefix();
pushPrefix();
}
}
blankLine(count);
return this;
}
Aggregations