use of com.vladsch.flexmark.ast.Node in project flexmark-java by vsch.
the class EnumeratedReferenceNodeRenderer method render.
private void render(EnumeratedReferenceLink node, NodeRendererContext context, HtmlWriter html) {
final String text = node.getText().toString();
if (text.isEmpty()) {
// placeholder for ordinal
html.text(String.valueOf(ordinal));
} else {
Node referenceFormat = enumeratedOrdinals.getFormatNode(text);
int wasOrdinal = ordinal;
ordinal = enumeratedOrdinals.getOrdinal(text);
if (referenceFormat != null) {
String title = new EnumRefTextCollectingVisitor(ordinal).collectAndGetText(referenceFormat);
html.withAttr().attr("href", "#" + text).attr("title", title).tag("a");
context.renderChildren(referenceFormat);
html.tag("/a");
} else {
// no format, just output type space ordinal
final String defaultText = String.format("%s %d", EnumeratedReferences.getType(text), ordinal);
html.withAttr().attr("href", "#" + text).attr("title", defaultText).tag("a");
html.text(defaultText);
html.tag("/a");
}
ordinal = wasOrdinal;
}
}
use of com.vladsch.flexmark.ast.Node in project flexmark-java by vsch.
the class ComboAutolinkSpecTest method testSpecTxt.
@Test
public void testSpecTxt() throws Exception {
if (!example.isFullSpecExample())
return;
final HtmlRenderer RENDERER = HtmlRenderer.builder(OPTIONS).build();
final Parser PARSER = Parser.builder(OPTIONS).build();
String source = readResource("/spec.txt");
Node node = PARSER.parse(source);
// String html = readResource("/table.html");
// assertRendering(source, html);
}
use of com.vladsch.flexmark.ast.Node in project flexmark-java by vsch.
the class YamlFrontMatterTest method literalValue2.
@Test
public void literalValue2() {
final String input = "---" + "\nliteral: |" + "\n - hello markdown!" + "\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!", data.get("literal").get(0));
assertRendering(input, rendered);
}
use of com.vladsch.flexmark.ast.Node in project flexmark-java by vsch.
the class YamlFrontMatterTest method listValues.
@Test
public void listValues() {
final String input = "---" + "\nlist:" + "\n - value1" + "\n - value2" + "\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("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 nonMatchedStartTag.
@Test
public void nonMatchedStartTag() {
final String input = "----\n" + "test";
final String rendered = "<hr />\n<p>test</p>\n";
AbstractYamlFrontMatterVisitor visitor = new AbstractYamlFrontMatterVisitor();
Node document = PARSER.parse(input);
visitor.visit(document);
Map<String, List<String>> data = visitor.getData();
assertTrue(data.isEmpty());
assertRendering(input, rendered);
}
Aggregations