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

org.commonmark.ext.gfm.strikethrough.StrikethroughExtension Maven / Gradle / Ivy

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

import org.commonmark.Extension;
import org.commonmark.renderer.text.TextContentRenderer;
import org.commonmark.renderer.text.TextContentNodeRendererContext;
import org.commonmark.renderer.text.TextContentNodeRendererFactory;
import org.commonmark.ext.gfm.strikethrough.internal.StrikethroughDelimiterProcessor;
import org.commonmark.ext.gfm.strikethrough.internal.StrikethroughHtmlNodeRenderer;
import org.commonmark.ext.gfm.strikethrough.internal.StrikethroughTextContentNodeRenderer;
import org.commonmark.renderer.html.HtmlRenderer;
import org.commonmark.renderer.html.HtmlNodeRendererContext;
import org.commonmark.renderer.html.HtmlNodeRendererFactory;
import org.commonmark.parser.Parser;
import org.commonmark.renderer.NodeRenderer;

/**
 * Extension for GFM strikethrough using ~~ (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 strikethrough text regions are turned into {@link Strikethrough} nodes. *

*/ public class StrikethroughExtension implements Parser.ParserExtension, HtmlRenderer.HtmlRendererExtension, TextContentRenderer.TextContentRendererExtension { private StrikethroughExtension() { } public static Extension create() { return new StrikethroughExtension(); } @Override public void extend(Parser.Builder parserBuilder) { parserBuilder.customDelimiterProcessor(new StrikethroughDelimiterProcessor()); } @Override public void extend(HtmlRenderer.Builder rendererBuilder) { rendererBuilder.nodeRendererFactory(new HtmlNodeRendererFactory() { @Override public NodeRenderer create(HtmlNodeRendererContext context) { return new StrikethroughHtmlNodeRenderer(context); } }); } @Override public void extend(TextContentRenderer.Builder rendererBuilder) { rendererBuilder.nodeRendererFactory(new TextContentNodeRendererFactory() { @Override public NodeRenderer create(TextContentNodeRendererContext context) { return new StrikethroughTextContentNodeRenderer(context); } }); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy