Search in sources :

Example 16 with HtmlRenderer

use of com.vladsch.flexmark.html.HtmlRenderer in project flexmark-java by vsch.

the class AttributeProviderSample2 method commonMark.

static String commonMark(String markdown) {
    MutableDataHolder options = new MutableDataSet();
    options.set(Parser.EXTENSIONS, Arrays.asList(new Extension[] { 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) 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)

Example 17 with HtmlRenderer

use of com.vladsch.flexmark.html.HtmlRenderer in project flexmark-java by vsch.

the class BasicSample method main.

public static void main(String[] args) {
    MutableDataSet options = new MutableDataSet();
    // uncomment to set optional extensions
    // options.set(Parser.EXTENSIONS, Arrays.asList(TablesExtension.create(), StrikethroughExtension.create()));
    // uncomment to convert soft-breaks to hard breaks
    // options.set(HtmlRenderer.SOFT_BREAK, "<br />\n");
    Parser parser = Parser.builder(options).build();
    HtmlRenderer renderer = HtmlRenderer.builder(options).build();
    // You can re-use parser and renderer instances
    Node document = parser.parse("This is *Sparta*");
    // "<p>This is <em>Sparta</em></p>\n"
    String html = renderer.render(document);
    System.out.println(html);
}
Also used : 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)

Example 18 with HtmlRenderer

use of com.vladsch.flexmark.html.HtmlRenderer in project flexmark-java by vsch.

the class XWikiMacrosSample method main.

public static void main(String[] args) {
    MutableDataHolder options = new MutableDataSet();
    options.set(Parser.EXTENSIONS, Arrays.asList(MacroExtension.create()));
    Parser parser = Parser.builder(options).build();
    HtmlRenderer renderer = HtmlRenderer.builder(options).build();
    String markdown = "markdown content here";
    Node document = parser.parse(markdown);
    XWikiMacrosSample macroProcessor = new XWikiMacrosSample();
    macroProcessor.visitor.visitChildren(document);
}
Also used : 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)

Example 19 with HtmlRenderer

use of com.vladsch.flexmark.html.HtmlRenderer in project flexmark-java by vsch.

the class CustomContextDataSample method main.

public static void main(String[] args) {
    final DataHolder options = PegdownOptionsAdapter.flexmarkOptions(Extensions.ALL, CustomExtension.create());
    Parser parser = Parser.builder(options).build();
    HtmlRenderer renderer = HtmlRenderer.builder(options).build();
    String markdown = "";
    XhtmlContent xhtmlContent = null;
    // You can re-use parser and renderer instances
    Document document = (Document) parser.parse(markdown);
    document.set(XHTML_CONTENT, xhtmlContent);
    // "<p>This is <em>Sparta</em></p>\n"
    String html = renderer.render(document);
    System.out.println(html);
}
Also used : DataHolder(com.vladsch.flexmark.util.options.DataHolder) MutableDataHolder(com.vladsch.flexmark.util.options.MutableDataHolder) HtmlRenderer(com.vladsch.flexmark.html.HtmlRenderer) Document(com.vladsch.flexmark.ast.Document) Parser(com.vladsch.flexmark.parser.Parser)

Example 20 with HtmlRenderer

use of com.vladsch.flexmark.html.HtmlRenderer in project flexmark-java by vsch.

the class ProfileEmulationFamilySamples method commonMark.

void commonMark() {
    Parser parser = Parser.builder().build();
    Node document = parser.parse("This is *Sparta*");
    HtmlRenderer renderer = HtmlRenderer.builder().build();
    // "<p>This is <em>Sparta</em></p>\n"
    renderer.render(document);
}
Also used : Node(com.vladsch.flexmark.ast.Node) HtmlRenderer(com.vladsch.flexmark.html.HtmlRenderer) 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