use of com.vladsch.flexmark.html.HtmlRenderer in project flexmark-java by vsch.
the class ComboTableSpecTest method testTable.
@Test
public void testTable() throws Exception {
if (!example.isFullSpecExample())
return;
final HtmlRenderer RENDERER = HtmlRenderer.builder(OPTIONS).build();
final Parser PARSER = Parser.builder(OPTIONS).build();
String source = readResource("/table.md");
String html = readResource("/table.html");
assertRendering(source, html);
}
use of com.vladsch.flexmark.html.HtmlRenderer in project cytoscape-impl by cytoscape.
the class HelpGenerator method generateArgumentHelp.
private void generateArgumentHelp(String namespace, String command, MessageHandler resultsText) {
String longDescription = availableCommands.getLongDescription(namespace, command);
String message = "";
// System.out.println("generateArgumentHelp");
if (longDescription != null) {
// Do we have an HTML string?
if (longDescription.trim().startsWith("<html>") || longDescription.trim().startsWith("<HTML>")) {
// Yes. Strip off the "<html></html>" wrapper
longDescription = longDescription.trim().substring(6);
longDescription = longDescription.substring(0, longDescription.length() - 7);
// System.out.println("longDescription(html) = "+longDescription);
} else {
// No, pass it through the markdown converter
Parser parser = Parser.builder().build();
Node document = parser.parse(longDescription);
HtmlRenderer renderer = HtmlRenderer.builder().build();
longDescription = renderer.render(document);
// System.out.println("longDescription(markdown) = "+longDescription);
}
message += longDescription;
}
List<String> argList = availableCommands.getArguments(namespace, command);
message += "<br/><br/><b>" + namespace + " " + command + "</b> arguments:";
// resultsText.appendMessage(commandArgs);
message += "<dl style='list-style-type:none;margin-top:0px;color:blue'>";
for (String arg : argList) {
message += "<dt>";
if (availableCommands.getArgRequired(namespace, command, arg)) {
message += "<b>" + arg + "</b>";
} else {
message += arg;
}
message += "=" + getTypeString(namespace, command, arg);
message += ": ";
message += "</dt>";
message += "<dd>";
message += normalizeArgDescription(availableCommands.getArgDescription(namespace, command, arg), availableCommands.getArgLongDescription(namespace, command, arg));
message += "</dd>";
}
resultsText.appendMessage(message + "</dl>");
}
use of com.vladsch.flexmark.html.HtmlRenderer in project flexmark-java by vsch.
the class TablesTest method attributeProviderIsApplied.
@Test
public void attributeProviderIsApplied() {
AttributeProviderFactory factory = new IndependentAttributeProviderFactory() {
@Override
public AttributeProvider create(LinkResolverContext context) {
return new AttributeProvider() {
@Override
public void setAttributes(Node node, AttributablePart part, Attributes attributes) {
if (node instanceof TableBlock) {
attributes.replaceValue("test", "block");
} else if (node instanceof TableHead) {
attributes.replaceValue("test", "head");
} else if (node instanceof TableBody) {
attributes.replaceValue("test", "body");
} else if (node instanceof TableRow) {
attributes.replaceValue("test", "row");
} else if (node instanceof TableCell) {
attributes.replaceValue("test", "cell");
}
}
};
}
};
HtmlRenderer renderer = HtmlRenderer.builder().attributeProviderFactory(factory).extensions(EXTENSIONS).build();
String rendered = renderer.render(PARSER.parse("Abc|Def\n---|---\n1|2"));
assertThat(rendered, is("<table test=\"block\">\n" + "<thead test=\"head\">\n" + "<tr test=\"row\"><th test=\"cell\">Abc</th><th test=\"cell\">Def</th></tr>\n" + "</thead>\n" + "<tbody test=\"body\">\n" + "<tr test=\"row\"><td test=\"cell\">1</td><td test=\"cell\">2</td></tr>\n" + "</tbody>\n" + "</table>\n"));
}
use of com.vladsch.flexmark.html.HtmlRenderer in project flexmark-java by vsch.
the class ComboParserTest 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("/commonMarkSpec.md");
Node node = PARSER.parse(source);
// String html = readResource("/table.html");
// assertRendering(source, html);
}
use of com.vladsch.flexmark.html.HtmlRenderer in project flexmark-java by vsch.
the class AttributeProviderSample method commonMark.
static String commonMark(String markdown) {
MutableDataHolder options = new MutableDataSet();
options.set(Parser.EXTENSIONS, Arrays.asList(new Extension[] { AutolinkExtension.create(), SampleExtension.create() }));
// change soft break to hard break
options.set(HtmlRenderer.SOFT_BREAK, "<br/>");
Parser parser = Parser.builder(options).build();
Node document = parser.parse(markdown);
HtmlRenderer renderer = HtmlRenderer.builder(options).build();
final String html = renderer.render(document);
return html;
}
Aggregations