Class HtmlRenderer.Builder

  • Enclosing class:
    HtmlRenderer

    public static class HtmlRenderer.Builder
    extends java.lang.Object
    Builder for configuring an HtmlRenderer. See methods for default configuration.
    • Field Detail

      • softbreak

        private java.lang.String softbreak
      • escapeHtml

        private boolean escapeHtml
      • sanitizeUrls

        private boolean sanitizeUrls
      • percentEncodeUrls

        private boolean percentEncodeUrls
    • Constructor Detail

      • Builder

        public Builder()
    • Method Detail

      • 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)
        Whether HtmlInline and HtmlBlock should be escaped, defaults to false.

        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)
        Whether Image src and Link href should be sanitized, defaults to false.
        Parameters:
        sanitizeUrls - true for sanitization, false for preserving raw attribute
        Returns:
        this
        Since:
        0.14.0
      • percentEncodeUrls

        public HtmlRenderer.Builder percentEncodeUrls​(boolean percentEncodeUrls)
        Whether URLs of link or images should be percent-encoded, defaults to false.

        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