Package org.commonmark.renderer.html
Class HtmlRenderer.Builder
- java.lang.Object
-
- org.commonmark.renderer.html.HtmlRenderer.Builder
-
- Enclosing class:
- HtmlRenderer
public static class HtmlRenderer.Builder extends java.lang.Object
Builder for configuring anHtmlRenderer
. See methods for default configuration.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<AttributeProviderFactory>
attributeProviderFactories
private boolean
escapeHtml
private java.util.List<HtmlNodeRendererFactory>
nodeRendererFactories
private boolean
percentEncodeUrls
private boolean
sanitizeUrls
private java.lang.String
softbreak
private UrlSanitizer
urlSanitizer
-
Constructor Summary
Constructors Constructor Description Builder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HtmlRenderer.Builder
attributeProviderFactory(AttributeProviderFactory attributeProviderFactory)
Add a factory for an attribute provider for adding/changing HTML attributes to the rendered tags.HtmlRenderer
build()
HtmlRenderer.Builder
escapeHtml(boolean escapeHtml)
HtmlRenderer.Builder
extensions(java.lang.Iterable<? extends Extension> extensions)
HtmlRenderer.Builder
nodeRendererFactory(HtmlNodeRendererFactory nodeRendererFactory)
Add a factory for instantiating a node renderer (done when rendering).HtmlRenderer.Builder
percentEncodeUrls(boolean percentEncodeUrls)
Whether URLs of link or images should be percent-encoded, defaults tofalse
.HtmlRenderer.Builder
sanitizeUrls(boolean sanitizeUrls)
HtmlRenderer.Builder
softbreak(java.lang.String softbreak)
The HTML to use for rendering a softbreak, defaults to"\n"
(meaning the rendered result doesn't have a line break).HtmlRenderer.Builder
urlSanitizer(UrlSanitizer urlSanitizer)
UrlSanitizer
used to filter URL's ifsanitizeUrls
is true.
-
-
-
Field Detail
-
softbreak
private java.lang.String softbreak
-
escapeHtml
private boolean escapeHtml
-
sanitizeUrls
private boolean sanitizeUrls
-
urlSanitizer
private UrlSanitizer urlSanitizer
-
percentEncodeUrls
private boolean percentEncodeUrls
-
attributeProviderFactories
private java.util.List<AttributeProviderFactory> attributeProviderFactories
-
nodeRendererFactories
private java.util.List<HtmlNodeRendererFactory> nodeRendererFactories
-
-
Method Detail
-
build
public HtmlRenderer build()
- Returns:
- the configured
HtmlRenderer
-
softbreak
public HtmlRenderer.Builder softbreak(java.lang.String softbreak)
The HTML to use for rendering a softbreak, defaults to"\n"
(meaning the rendered result doesn't have a line break).Set it to
"<br>"
(or"<br />"
to make them hard breaks.Set it to
" "
to ignore line wrapping in the source.- Parameters:
softbreak
- HTML for softbreak- Returns:
this
-
escapeHtml
public HtmlRenderer.Builder escapeHtml(boolean escapeHtml)
WhetherHtmlInline
andHtmlBlock
should be escaped, defaults tofalse
.Note that
HtmlInline
is only a tag itself, not the text between an opening tag and a closing tag. So markup in the text will be parsed as normal and is not affected by this option.- Parameters:
escapeHtml
- true for escaping, false for preserving raw HTML- Returns:
this
-
sanitizeUrls
public HtmlRenderer.Builder sanitizeUrls(boolean sanitizeUrls)
- Parameters:
sanitizeUrls
- true for sanitization, false for preserving raw attribute- Returns:
this
- Since:
- 0.14.0
-
urlSanitizer
public HtmlRenderer.Builder urlSanitizer(UrlSanitizer urlSanitizer)
UrlSanitizer
used to filter URL's ifsanitizeUrls
is true.
-
percentEncodeUrls
public HtmlRenderer.Builder percentEncodeUrls(boolean percentEncodeUrls)
Whether URLs of link or images should be percent-encoded, defaults tofalse
.If enabled, the following is done:
- Existing percent-encoded parts are preserved (e.g. "%20" is kept as "%20")
- Reserved characters such as "/" are preserved, except for "[" and "]" (see encodeURI in JS)
- Unreserved characters such as "a" are preserved
- Other characters such umlauts are percent-encoded
- Parameters:
percentEncodeUrls
- true to percent-encode, false for leaving as-is- Returns:
this
-
attributeProviderFactory
public HtmlRenderer.Builder attributeProviderFactory(AttributeProviderFactory attributeProviderFactory)
Add a factory for an attribute provider for adding/changing HTML attributes to the rendered tags.- Parameters:
attributeProviderFactory
- the attribute provider factory to add- Returns:
this
-
nodeRendererFactory
public HtmlRenderer.Builder nodeRendererFactory(HtmlNodeRendererFactory nodeRendererFactory)
Add a factory for instantiating a node renderer (done when rendering). This allows to override the rendering of node types or define rendering for custom node types.If multiple node renderers for the same node type are created, the one from the factory that was added first "wins". (This is how the rendering for core node types can be overridden; the default rendering comes last.)
- Parameters:
nodeRendererFactory
- the factory for creating a node renderer- Returns:
this
-
extensions
public HtmlRenderer.Builder extensions(java.lang.Iterable<? extends Extension> extensions)
- Parameters:
extensions
- extensions to use on this HTML renderer- Returns:
this
-
-