APIdia Launch Partner
Top Description Inners Fields Constructors Methods
jdk.internal.org.commonmark.renderer.html

public Class HtmlRenderer

extends Object
implements Renderer
Class Inheritance
All Implemented Interfaces
jdk.internal.org.commonmark.renderer.Renderer
Imports
jdk.internal.org.commonmark.Extension, jdk.internal.org.commonmark.internal.renderer.NodeRendererMap, jdk.internal.org.commonmark.internal.util.Escaping, jdk.internal.org.commonmark.node.*, jdk.internal.org.commonmark.renderer.NodeRenderer, .Renderer, java.util.ArrayList, .LinkedHashMap, .List, .Map

Renders a tree of nodes to HTML.

Start with the builder method to configure the renderer. Example:


HtmlRenderer renderer = HtmlRenderer.builder().escapeHtml(true).build();
renderer.render(node);

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
HtmlRenderer.Builder

Builder for configuring an HtmlRenderer.

public static interface
private class

Field Summary

Modifier and TypeField and Description
private final List<AttributeProviderFactory>
private final boolean
private final List<HtmlNodeRendererFactory>
private final boolean
private final boolean
private final String
private final UrlSanitizer

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static HtmlRenderer.Builder

Returns:

a builder
builder
()

Create a new builder for configuring an HtmlRenderer.

public void
render(Node node, Appendable output)

Implements jdk.internal.org.commonmark.renderer.Renderer.render.

Render the tree of nodes to output.

public String
render(Node node)

Implements jdk.internal.org.commonmark.renderer.Renderer.render.

Render the tree of nodes to string.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

attributeProviderFactoriesback to summary
private final List<AttributeProviderFactory> attributeProviderFactories
escapeHtmlback to summary
private final boolean escapeHtml
nodeRendererFactoriesback to summary
private final List<HtmlNodeRendererFactory> nodeRendererFactories
percentEncodeUrlsback to summary
private final boolean percentEncodeUrls
sanitizeUrlsback to summary
private final boolean sanitizeUrls
softbreakback to summary
private final String softbreak
urlSanitizerback to summary
private final UrlSanitizer urlSanitizer

Constructor Detail

HtmlRendererback to summary
private HtmlRenderer(HtmlRenderer.Builder builder)

Method Detail

builderback to summary
public static HtmlRenderer.Builder builder()

Create a new builder for configuring an HtmlRenderer.

Returns:HtmlRenderer.Builder

a builder

renderback to summary
public void render(Node node, Appendable output)

Implements jdk.internal.org.commonmark.renderer.Renderer.render.

Doc from jdk.internal.org.commonmark.renderer.Renderer.render.

Render the tree of nodes to output.

Annotations
@Override
renderback to summary
public String render(Node node)

Implements jdk.internal.org.commonmark.renderer.Renderer.render.

Doc from jdk.internal.org.commonmark.renderer.Renderer.render.

Render the tree of nodes to string.

Annotations
@Override
jdk.internal.org.commonmark.renderer.html back to summary

public Class HtmlRenderer.Builder

extends Object
Class Inheritance
  • java.lang.Object
  • jdk.internal.org.commonmark.renderer.html.HtmlRenderer.Builder

Builder for configuring an HtmlRenderer. See methods for default configuration.

Field Summary

Modifier and TypeField and Description
private List<AttributeProviderFactory>
private boolean
private List<HtmlNodeRendererFactory>
private boolean
private boolean
private String
private UrlSanitizer

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public HtmlRenderer.Builder

Returns:

this
attributeProviderFactory
(AttributeProviderFactory
the attribute provider factory to add
attributeProviderFactory
)

Add a factory for an attribute provider for adding/changing HTML attributes to the rendered tags.

public HtmlRenderer
build()

Returns: the configured HtmlRenderer

public HtmlRenderer.Builder

Returns:

this
escapeHtml
(boolean
true for escaping, false for preserving raw HTML
escapeHtml
)

Whether HtmlInline and HtmlBlock should be escaped, defaults to false.

public HtmlRenderer.Builder
extensions(Iterable<? extends Extension>
extensions to use on this HTML renderer
extensions
)

Returns: this

public HtmlRenderer.Builder

Returns:

this
nodeRendererFactory
(HtmlNodeRendererFactory
the factory for creating a node renderer
nodeRendererFactory
)

Add a factory for instantiating a node renderer (done when rendering).

public HtmlRenderer.Builder

Returns:

this
percentEncodeUrls
(boolean
true to percent-encode, false for leaving as-is
percentEncodeUrls
)

Whether URLs of link or images should be percent-encoded, defaults to false.

public HtmlRenderer.Builder

Returns:

this
sanitizeUrls
(boolean
true for sanitization, false for preserving raw attribute
sanitizeUrls
)

Whether Image src and Link href should be sanitized, defaults to false.

public HtmlRenderer.Builder

Returns:

this
softbreak
(String
HTML for softbreak
softbreak
)

The HTML to use for rendering a softbreak, defaults to "\n" (meaning the rendered result doesn't have a line break).

public HtmlRenderer.Builder

Returns:

this
urlSanitizer
(UrlSanitizer
Filterer used to filter Image src and Link.
urlSanitizer
)

UrlSanitizer used to filter URL's if sanitizeUrls is true.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

attributeProviderFactoriesback to summary
private List<AttributeProviderFactory> attributeProviderFactories
escapeHtmlback to summary
private boolean escapeHtml
nodeRendererFactoriesback to summary
private List<HtmlNodeRendererFactory> nodeRendererFactories
percentEncodeUrlsback to summary
private boolean percentEncodeUrls
sanitizeUrlsback to summary
private boolean sanitizeUrls
softbreakback to summary
private String softbreak
urlSanitizerback to summary
private UrlSanitizer urlSanitizer

Constructor Detail

Builderback to summary
public Builder()

Method Detail

attributeProviderFactoryback to summary
public HtmlRenderer.Builder attributeProviderFactory(AttributeProviderFactory attributeProviderFactory)

Add a factory for an attribute provider for adding/changing HTML attributes to the rendered tags.

Parameters
attributeProviderFactory:AttributeProviderFactory

the attribute provider factory to add

Returns:HtmlRenderer.Builder

this

buildback to summary
public HtmlRenderer build()
Returns:HtmlRenderer

the configured HtmlRenderer

escapeHtmlback to summary
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:boolean

true for escaping, false for preserving raw HTML

Returns:HtmlRenderer.Builder

this

extensionsback to summary
public HtmlRenderer.Builder extensions(Iterable<? extends Extension> extensions)
Parameters
extensions:Iterable<? extends Extension>

extensions to use on this HTML renderer

Returns:HtmlRenderer.Builder

this

nodeRendererFactoryback to summary
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:HtmlNodeRendererFactory

the factory for creating a node renderer

Returns:HtmlRenderer.Builder

this

percentEncodeUrlsback to summary
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:boolean

true to percent-encode, false for leaving as-is

Returns:HtmlRenderer.Builder

this

sanitizeUrlsback to summary
public HtmlRenderer.Builder sanitizeUrls(boolean sanitizeUrls)

Whether Image src and Link href should be sanitized, defaults to false.

Parameters
sanitizeUrls:boolean

true for sanitization, false for preserving raw attribute

Returns:HtmlRenderer.Builder

this

Since
0.14.0
softbreakback to summary
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:String

HTML for softbreak

Returns:HtmlRenderer.Builder

this

urlSanitizerback to summary
public HtmlRenderer.Builder urlSanitizer(UrlSanitizer urlSanitizer)

UrlSanitizer used to filter URL's if sanitizeUrls is true.

Parameters
urlSanitizer:UrlSanitizer

Filterer used to filter Image src and Link.

Returns:HtmlRenderer.Builder

this

Since
0.14.0
jdk.internal.org.commonmark.renderer.html back to summary

public Interface HtmlRenderer.HtmlRendererExtension

extends Extension
Known Direct Implementers
jdk.internal.org.commonmark.ext.gfm.tables.TablesExtension

Extension for HtmlRenderer.

Method Summary

Modifier and TypeMethod and Description
public void
extend(HtmlRenderer.Builder rendererBuilder)

Method Detail

extendback to summary
public void extend(HtmlRenderer.Builder rendererBuilder)
jdk.internal.org.commonmark.renderer.html back to summary

private Class HtmlRenderer.RendererContext

extends Object
implements HtmlNodeRendererContext, AttributeProviderContext
Class Inheritance
  • java.lang.Object
  • jdk.internal.org.commonmark.renderer.html.HtmlRenderer.RendererContext
All Implemented Interfaces
jdk.internal.org.commonmark.renderer.html.AttributeProviderContext, jdk.internal.org.commonmark.renderer.html.HtmlNodeRendererContext

Field Summary

Modifier and TypeField and Description
private final List<AttributeProvider>
private final HtmlWriter
private final NodeRendererMap

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public String
public Map<String, String>
extendAttributes(Node node, String tagName, Map<String, String> attributes)

Implements jdk.internal.org.commonmark.renderer.html.HtmlNodeRendererContext.extendAttributes.

Let extensions modify the HTML tag attributes.

public String
public HtmlWriter
public void
render(Node node)

Implements jdk.internal.org.commonmark.renderer.html.HtmlNodeRendererContext.render.

Render the specified node and its children using the configured renderers.

private void
setCustomAttributes(Node node, String tagName, Map<String, String> attrs)

public boolean
public boolean
public UrlSanitizer
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

attributeProvidersback to summary
private final List<AttributeProvider> attributeProviders
htmlWriterback to summary
private final HtmlWriter htmlWriter
nodeRendererMapback to summary
private final NodeRendererMap nodeRendererMap

Constructor Detail

RendererContextback to summary
private RendererContext(HtmlWriter htmlWriter)

Method Detail

encodeUrlback to summary
public String encodeUrl(String url)

Implements jdk.internal.org.commonmark.renderer.html.HtmlNodeRendererContext.encodeUrl.

Annotations
@Override
extendAttributesback to summary
public Map<String, String> extendAttributes(Node node, String tagName, Map<String, String> attributes)

Implements jdk.internal.org.commonmark.renderer.html.HtmlNodeRendererContext.extendAttributes.

Doc from jdk.internal.org.commonmark.renderer.html.HtmlNodeRendererContext.extendAttributes.

Let extensions modify the HTML tag attributes.

Annotations
@Override
getSoftbreakback to summary
public String getSoftbreak()

Implements jdk.internal.org.commonmark.renderer.html.HtmlNodeRendererContext.getSoftbreak.

Annotations
@Override
getWriterback to summary
public HtmlWriter getWriter()

Implements jdk.internal.org.commonmark.renderer.html.HtmlNodeRendererContext.getWriter.

Annotations
@Override
renderback to summary
public void render(Node node)

Implements jdk.internal.org.commonmark.renderer.html.HtmlNodeRendererContext.render.

Doc from jdk.internal.org.commonmark.renderer.html.HtmlNodeRendererContext.render.

Render the specified node and its children using the configured renderers. This should be used to render child nodes; be careful not to pass the node that is being rendered, that would result in an endless loop.

Annotations
@Override
setCustomAttributesback to summary
private void setCustomAttributes(Node node, String tagName, Map<String, String> attrs)
shouldEscapeHtmlback to summary
public boolean shouldEscapeHtml()

Implements jdk.internal.org.commonmark.renderer.html.HtmlNodeRendererContext.shouldEscapeHtml.

Annotations
@Override
shouldSanitizeUrlsback to summary
public boolean shouldSanitizeUrls()

Implements jdk.internal.org.commonmark.renderer.html.HtmlNodeRendererContext.shouldSanitizeUrls.

Annotations
@Override
urlSanitizerback to summary
public UrlSanitizer urlSanitizer()

Implements jdk.internal.org.commonmark.renderer.html.HtmlNodeRendererContext.urlSanitizer.

Annotations
@Override