Class MarkdownFilter
java.lang.Object
org.shredzone.commons.text.filter.MarkdownFilter
- All Implemented Interfaces:
Function<CharSequence,CharSequence>,TextFilter
- Direct Known Subclasses:
GithubFlavoredMarkdownFilter
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapply(CharSequence text)Applies the filter on aCharSequenceand returns a newCharSequencewith the modified text.protected List<org.commonmark.Extension>Creates a list of markdown extensions to be used.protected org.commonmark.renderer.html.HtmlRenderer.BuilderCreates and configures a commonmarkHtmlRenderer.Builderto be used for rendering HTML.protected org.commonmark.parser.Parser.BuilderCreates and configures a commonmarkParser.Builderto be used for parsing.voidsetAnalyzer(LinkAnalyzer analyzer)Sets aLinkAnalyzerto be used for converting links and image source URLs.voidsetPreClass(String preClass)Class name to be added to each fenced code block.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.shredzone.commons.text.TextFilter
toStringBuilder
-
Constructor Details
-
MarkdownFilter
public MarkdownFilter()
-
-
Method Details
-
setAnalyzer
Sets aLinkAnalyzerto be used for converting links and image source URLs.- Parameters:
analyzer-LinkAnalyzerto be used
-
setPreClass
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
Description copied from interface:TextFilterApplies the filter on aCharSequenceand returns a newCharSequencewith the modified text.- Specified by:
applyin interfaceFunction<CharSequence,CharSequence>- Specified by:
applyin interfaceTextFilter- Parameters:
text-CharSequencewith the contents to be filtered. If this is aStringBuilderinstance, its contents may have changed after invocation, and this instance should not be used any more.- Returns:
CharSequencewith the filtered text.
-
createParserBuilder
Creates and configures a commonmarkParser.Builderto be used for parsing.Note that this method is commonmark specific and might be removed in future versions.
- Returns:
Parser.Builderto be used for the markup parser
-
createHtmlRendererBuilder
Creates and configures a commonmarkHtmlRenderer.Builderto be used for rendering HTML. The default implementation adds anAttributeProviderthat uses theLinkAnalyzerfor analyzing links and generating HTML attributes.Note that this method is commonmark specific and might be removed in future versions.
- Returns:
HtmlRenderer.Builderto be used for HTML rendering
-
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
Listof extensions - Since:
- 2.8
-