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.ObjectBuilder for configuring anHtmlRenderer. See methods for default configuration.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<AttributeProviderFactory>attributeProviderFactoriesprivate booleanescapeHtmlprivate java.util.List<HtmlNodeRendererFactory>nodeRendererFactoriesprivate booleanomitSingleParagraphPprivate booleanpercentEncodeUrlsprivate booleansanitizeUrlsprivate java.lang.Stringsoftbreakprivate UrlSanitizerurlSanitizer
-
Constructor Summary
Constructors Constructor Description Builder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HtmlRenderer.BuilderattributeProviderFactory(AttributeProviderFactory attributeProviderFactory)Add a factory for an attribute provider for adding/changing HTML attributes to the rendered tags.HtmlRendererbuild()HtmlRenderer.BuilderescapeHtml(boolean escapeHtml)HtmlRenderer.Builderextensions(java.lang.Iterable<? extends Extension> extensions)HtmlRenderer.BuildernodeRendererFactory(HtmlNodeRendererFactory nodeRendererFactory)Add a factory for instantiating a node renderer (done when rendering).HtmlRenderer.BuilderomitSingleParagraphP(boolean omitSingleParagraphP)Whether documents that only contain a single paragraph should be rendered without the<p>tag.HtmlRenderer.BuilderpercentEncodeUrls(boolean percentEncodeUrls)Whether URLs of link or images should be percent-encoded, defaults tofalse.HtmlRenderer.BuildersanitizeUrls(boolean sanitizeUrls)HtmlRenderer.Buildersoftbreak(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.BuilderurlSanitizer(UrlSanitizer urlSanitizer)UrlSanitizerused to filter URL's ifsanitizeUrlsis 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
-
omitSingleParagraphP
private boolean omitSingleParagraphP
-
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)
WhetherHtmlInlineandHtmlBlockshould be escaped, defaults tofalse.Note that
HtmlInlineis 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)
UrlSanitizerused to filter URL's ifsanitizeUrlsis 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
-
omitSingleParagraphP
public HtmlRenderer.Builder omitSingleParagraphP(boolean omitSingleParagraphP)
Whether documents that only contain a single paragraph should be rendered without the<p>tag. Set totrueto render without the tag; the default offalsealways 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
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
-
-