Class HtmlRenderer.Builder

java.lang.Object
org.commonmark.renderer.html.HtmlRenderer.Builder
Enclosing class:
HtmlRenderer

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

    • softbreak

      private String softbreak
    • escapeHtml

      private boolean escapeHtml
    • sanitizeUrls

      private boolean sanitizeUrls
    • urlSanitizer

      private UrlSanitizer urlSanitizer
    • percentEncodeUrls

      private boolean percentEncodeUrls
    • attributeProviderFactories

      private List<AttributeProviderFactory> attributeProviderFactories
    • nodeRendererFactories

      private List<HtmlNodeRendererFactory> nodeRendererFactories
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • build

      public HtmlRenderer build()
      Returns:
      the configured HtmlRenderer
    • softbreak

      public HtmlRenderer.Builder softbreak(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
    • urlSanitizer

      public HtmlRenderer.Builder urlSanitizer(UrlSanitizer urlSanitizer)
      UrlSanitizer used to filter URL's if sanitizeUrls is true.
      Parameters:
      urlSanitizer - Filterer used to filter Image src and Link.
      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(Iterable<? extends Extension> extensions)
      Parameters:
      extensions - extensions to use on this HTML renderer
      Returns:
      this