All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.commonmark.ext.gfm.tables.TablesExtension Maven / Gradle / Ivy

There is a newer version: 0.17.0
Show newest version
package org.commonmark.ext.gfm.tables;

import org.commonmark.Extension;
import org.commonmark.ext.gfm.tables.internal.TableBlockParser;
import org.commonmark.ext.gfm.tables.internal.TableHtmlNodeRenderer;
import org.commonmark.ext.gfm.tables.internal.TableTextContentNodeRenderer;
import org.commonmark.parser.Parser;
import org.commonmark.renderer.NodeRenderer;
import org.commonmark.renderer.html.HtmlNodeRendererContext;
import org.commonmark.renderer.html.HtmlNodeRendererFactory;
import org.commonmark.renderer.html.HtmlRenderer;
import org.commonmark.renderer.text.TextContentNodeRendererContext;
import org.commonmark.renderer.text.TextContentNodeRendererFactory;
import org.commonmark.renderer.text.TextContentRenderer;

/**
 * Extension for GFM tables using "|" pipes (GitHub Flavored Markdown).
 * 

* Create it with {@link #create()} and then configure it on the builders * ({@link org.commonmark.parser.Parser.Builder#extensions(Iterable)}, * {@link HtmlRenderer.Builder#extensions(Iterable)}). *

*

* The parsed tables are turned into {@link TableBlock} blocks. *

* * @see Tables (extension) in GitHub Flavored Markdown Spec */ public class TablesExtension implements Parser.ParserExtension, HtmlRenderer.HtmlRendererExtension, TextContentRenderer.TextContentRendererExtension { private TablesExtension() { } public static Extension create() { return new TablesExtension(); } @Override public void extend(Parser.Builder parserBuilder) { parserBuilder.customBlockParserFactory(new TableBlockParser.Factory()); } @Override public void extend(HtmlRenderer.Builder rendererBuilder) { rendererBuilder.nodeRendererFactory(new HtmlNodeRendererFactory() { @Override public NodeRenderer create(HtmlNodeRendererContext context) { return new TableHtmlNodeRenderer(context); } }); } @Override public void extend(TextContentRenderer.Builder rendererBuilder) { rendererBuilder.nodeRendererFactory(new TextContentNodeRendererFactory() { @Override public NodeRenderer create(TextContentNodeRendererContext context) { return new TableTextContentNodeRenderer(context); } }); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy