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
-
Method Summary
Modifier and TypeMethodDescriptionapply(CharSequence text)
Applies the filter on aCharSequence
and returns a newCharSequence
with the modified text.protected List<org.commonmark.Extension>
Creates a list of markdown extensions to be used.protected org.commonmark.renderer.html.HtmlRenderer.Builder
Creates and configures a commonmarkHtmlRenderer.Builder
to be used for rendering HTML.protected org.commonmark.parser.Parser.Builder
Creates and configures a commonmarkParser.Builder
to be used for parsing.void
setAnalyzer(LinkAnalyzer analyzer)
Sets aLinkAnalyzer
to be used for converting links and image source URLs.void
setPreClass(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, wait
Methods inherited from interface org.shredzone.commons.text.TextFilter
toStringBuilder
-
Constructor Details
-
MarkdownFilter
public MarkdownFilter()
-
-
Method Details
-
setAnalyzer
Sets aLinkAnalyzer
to be used for converting links and image source URLs.- Parameters:
analyzer
-LinkAnalyzer
to 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:TextFilter
Applies the filter on aCharSequence
and returns a newCharSequence
with the modified text.- Specified by:
apply
in interfaceFunction<CharSequence,CharSequence>
- Specified by:
apply
in interfaceTextFilter
- Parameters:
text
-CharSequence
with the contents to be filtered. If this is aStringBuilder
instance, its contents may have changed after invocation, and this instance should not be used any more.- Returns:
CharSequence
with the filtered text.
-
createParserBuilder
Creates and configures a commonmarkParser.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
Creates and configures a commonmarkHtmlRenderer.Builder
to be used for rendering HTML. The default implementation adds anAttributeProvider
that uses theLinkAnalyzer
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
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
-