Search in sources :

Example 11 with HtmlRenderer

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);
}
Also used : HtmlRenderer(com.vladsch.flexmark.html.HtmlRenderer) Parser(com.vladsch.flexmark.parser.Parser) Test(org.junit.Test)

Example 12 with HtmlRenderer

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>");
}
Also used : Node(com.vladsch.flexmark.ast.Node) HtmlRenderer(com.vladsch.flexmark.html.HtmlRenderer) Parser(com.vladsch.flexmark.parser.Parser)

Example 13 with HtmlRenderer

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"));
}
Also used : Node(com.vladsch.flexmark.ast.Node) Attributes(com.vladsch.flexmark.util.html.Attributes) AttributablePart(com.vladsch.flexmark.html.renderer.AttributablePart) AttributeProviderFactory(com.vladsch.flexmark.html.AttributeProviderFactory) IndependentAttributeProviderFactory(com.vladsch.flexmark.html.IndependentAttributeProviderFactory) IndependentAttributeProviderFactory(com.vladsch.flexmark.html.IndependentAttributeProviderFactory) LinkResolverContext(com.vladsch.flexmark.html.renderer.LinkResolverContext) HtmlRenderer(com.vladsch.flexmark.html.HtmlRenderer) AttributeProvider(com.vladsch.flexmark.html.AttributeProvider) Test(org.junit.Test)

Example 14 with HtmlRenderer

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);
}
Also used : Node(com.vladsch.flexmark.ast.Node) HtmlRenderer(com.vladsch.flexmark.html.HtmlRenderer) Parser(com.vladsch.flexmark.parser.Parser) Test(org.junit.Test)

Example 15 with HtmlRenderer

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;
}
Also used : Extension(com.vladsch.flexmark.Extension) AutolinkExtension(com.vladsch.flexmark.ext.autolink.AutolinkExtension) MutableDataHolder(com.vladsch.flexmark.util.options.MutableDataHolder) Node(com.vladsch.flexmark.ast.Node) HtmlRenderer(com.vladsch.flexmark.html.HtmlRenderer) MutableDataSet(com.vladsch.flexmark.util.options.MutableDataSet) Parser(com.vladsch.flexmark.parser.Parser)

Aggregations

HtmlRenderer (com.vladsch.flexmark.html.HtmlRenderer)28 Parser (com.vladsch.flexmark.parser.Parser)27 Node (com.vladsch.flexmark.ast.Node)21 MutableDataSet (com.vladsch.flexmark.util.options.MutableDataSet)15 MutableDataHolder (com.vladsch.flexmark.util.options.MutableDataHolder)7 Test (org.junit.Test)6 Extension (com.vladsch.flexmark.Extension)2 Document (com.vladsch.flexmark.ast.Document)2 AutolinkExtension (com.vladsch.flexmark.ext.autolink.AutolinkExtension)1 JekyllTag (com.vladsch.flexmark.ext.jekyll.tag.JekyllTag)1 CustomNodeFormatter (com.vladsch.flexmark.formatter.CustomNodeFormatter)1 AttributeProvider (com.vladsch.flexmark.html.AttributeProvider)1 AttributeProviderFactory (com.vladsch.flexmark.html.AttributeProviderFactory)1 IndependentAttributeProviderFactory (com.vladsch.flexmark.html.IndependentAttributeProviderFactory)1 AttributablePart (com.vladsch.flexmark.html.renderer.AttributablePart)1 LinkResolverContext (com.vladsch.flexmark.html.renderer.LinkResolverContext)1 Attributes (com.vladsch.flexmark.util.html.Attributes)1 DataHolder (com.vladsch.flexmark.util.options.DataHolder)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1