Package org.commonmark.renderer.html
Class HtmlRenderer.Builder
java.lang.Object
org.commonmark.renderer.html.HtmlRenderer.Builder
- Enclosing class:
HtmlRenderer
Builder for configuring an
HtmlRenderer
. See methods for default configuration.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate List
<AttributeProviderFactory> private boolean
private List
<HtmlNodeRendererFactory> private boolean
private boolean
private boolean
private String
private UrlSanitizer
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionattributeProviderFactory
(AttributeProviderFactory attributeProviderFactory) Add a factory for an attribute provider for adding/changing HTML attributes to the rendered tags.build()
escapeHtml
(boolean escapeHtml) extensions
(Iterable<? extends Extension> extensions) nodeRendererFactory
(HtmlNodeRendererFactory nodeRendererFactory) Add a factory for instantiating a node renderer (done when rendering).omitSingleParagraphP
(boolean omitSingleParagraphP) Whether documents that only contain a single paragraph should be rendered without the<p>
tag.percentEncodeUrls
(boolean percentEncodeUrls) Whether URLs of link or images should be percent-encoded, defaults tofalse
.sanitizeUrls
(boolean sanitizeUrls) The HTML to use for rendering a softbreak, defaults to"\n"
(meaning the rendered result doesn't have a line break).urlSanitizer
(UrlSanitizer urlSanitizer) UrlSanitizer
used to filter URL's ifsanitizeUrls
is true.
-
Field Details
-
softbreak
-
escapeHtml
private boolean escapeHtml -
sanitizeUrls
private boolean sanitizeUrls -
urlSanitizer
-
percentEncodeUrls
private boolean percentEncodeUrls -
omitSingleParagraphP
private boolean omitSingleParagraphP -
attributeProviderFactories
-
nodeRendererFactories
-
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
build
- Returns:
- the configured
HtmlRenderer
-
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
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
- Parameters:
sanitizeUrls
- true for sanitization, false for preserving raw attribute- Returns:
this
- Since:
- 0.14.0
-
urlSanitizer
UrlSanitizer
used to filter URL's ifsanitizeUrls
is true. -
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
-
omitSingleParagraphP
Whether documents that only contain a single paragraph should be rendered without the<p>
tag. Set totrue
to render without the tag; the default offalse
always renders the tag.- 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
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
- Parameters:
extensions
- extensions to use on this HTML renderer- Returns:
this
-