Class MarkdownFilter

java.lang.Object
org.shredzone.commons.text.filter.MarkdownFilter
All Implemented Interfaces:
Function<CharSequence,​CharSequence>, TextFilter
Direct Known Subclasses:
GithubFlavoredMarkdownFilter

public class MarkdownFilter extends Object implements TextFilter
A filter that converts Markdown to HTML.

Uses commonmark-java for converting Markdown to HTML.

Author:
Richard "Shred" Körber
See Also:
commonmark-java
  • Constructor Details

  • Method Details

    • setAnalyzer

      public void setAnalyzer(@Nullable LinkAnalyzer analyzer)
      Sets a LinkAnalyzer to be used for converting links and image source URLs.
      Parameters:
      analyzer - LinkAnalyzer to be used
    • setPreClass

      public void setPreClass(@Nullable String preClass)
      Class name to be added to each fenced code block. This can be used for syntax highlighters like prettify.
      Parameters:
      preClass - Name of the css class to be added to each fenced block.
      Since:
      2.4
    • apply

      public CharSequence apply(CharSequence text)
      Description copied from interface: TextFilter
      Applies the filter on a CharSequence and returns a new CharSequence with the modified text.
      Specified by:
      apply in interface Function<CharSequence,​CharSequence>
      Specified by:
      apply in interface TextFilter
      Parameters:
      text - CharSequence with the contents to be filtered. If this is a StringBuilder instance, its contents may have changed after invocation, and this instance should not be used any more.
      Returns:
      CharSequence with the filtered text.
    • createParserBuilder

      protected org.commonmark.parser.Parser.Builder createParserBuilder()
      Creates and configures a commonmark Parser.Builder to be used for parsing.

      Note that this method is commonmark specific and might be removed in future versions.

      Returns:
      Parser.Builder to be used for the markup parser
    • createHtmlRendererBuilder

      protected org.commonmark.renderer.html.HtmlRenderer.Builder createHtmlRendererBuilder()
      Creates and configures a commonmark HtmlRenderer.Builder to be used for rendering HTML. The default implementation adds an AttributeProvider that uses the LinkAnalyzer for analyzing links and generating HTML attributes.

      Note that this method is commonmark specific and might be removed in future versions.

      Returns:
      HtmlRenderer.Builder to be used for HTML rendering
    • createExtensionList

      @OverrideMustInvoke protected List<org.commonmark.Extension> createExtensionList()
      Creates a list of markdown extensions to be used. By default this list is empty. Subclasses may add extensions to the list.

      Note that this method is commonmark specific and might be removed in future versions.

      Returns:
      Modifiable List of extensions
      Since:
      2.8