Package com.vladsch.flexmark.html
Class HtmlRenderer.MainNodeRenderer
- java.lang.Object
-
- com.vladsch.flexmark.html.NodeRendererSubContext
-
- com.vladsch.flexmark.html.HtmlRenderer.MainNodeRenderer
-
- All Implemented Interfaces:
Disposable
,LinkResolverBasicContext
,LinkResolverContext
,NodeRendererContext
- Enclosing class:
- HtmlRenderer
private class HtmlRenderer.MainNodeRenderer extends NodeRendererSubContext implements NodeRendererContext, Disposable
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
HtmlRenderer.MainNodeRenderer.SubNodeRenderer
-
Field Summary
Fields Modifier and Type Field Description private AttributeProvider[]
attributeProviders
private Document
document
(package private) HtmlIdGenerator
htmlIdGenerator
private LinkResolver[]
myLinkResolvers
private DataHolder
options
private RenderingPhase
phase
private java.util.List<PhasedNodeRenderer>
phasedRenderers
private java.util.Map<java.lang.Class<?>,NodeRenderingHandlerWrapper>
renderers
private java.util.Set<RenderingPhase>
renderingPhases
private java.util.HashMap<LinkType,java.util.HashMap<java.lang.String,ResolvedLink>>
resolvedLinkMap
-
Fields inherited from class com.vladsch.flexmark.html.NodeRendererSubContext
doNotRenderLinksNesting, htmlWriter, renderingHandlerWrapper, renderingNode
-
-
Constructor Summary
Constructors Constructor Description MainNodeRenderer(DataHolder options, HtmlWriter htmlWriter, Document document)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
delegateRender()
pass node rendering to previously registered handlervoid
dispose()
@NotNull java.lang.String
encodeUrl(@NotNull java.lang.CharSequence url)
@NotNull MutableAttributes
extendRenderingNodeAttributes(@NotNull AttributablePart part, Attributes attributes)
Extend the attributes by extensions for the node being currently rendered.@NotNull MutableAttributes
extendRenderingNodeAttributes(@NotNull Node node, @NotNull AttributablePart part, Attributes attributes)
Extend the attributes by extensions for the node being currently rendered.@NotNull Node
getCurrentNode()
@NotNull NodeRendererContext
getDelegatedSubContext(boolean inheritIndent)
Creates a child rendering context that can be used to collect rendered html text of the previously registered node renderer.@NotNull Document
getDocument()
@NotNull HtmlRendererOptions
getHtmlOptions()
java.lang.String
getNodeId(@NotNull Node node)
Get the id attribute for the given node.@NotNull DataHolder
getOptions()
Get the current rendering contextDataHolder
.@NotNull RenderingPhase
getRenderingPhase()
@NotNull NodeRendererContext
getSubContext(boolean inheritIndent)
Creates a child rendering context that can be used to collect rendered html text.void
render(@NotNull Node node)
Render the specified node and its children using the configured renderers.(package private) void
renderByPreviousHandler(NodeRendererSubContext subContext)
void
renderChildren(@NotNull Node parent)
Render the children of the node, used by custom renderersprotected void
renderChildrenNode(Node parent, NodeRendererSubContext subContext)
(package private) void
renderNode(Node node, NodeRendererSubContext subContext)
@NotNull ResolvedLink
resolveLink(@NotNull LinkType linkType, @NotNull java.lang.CharSequence url, Attributes attributes, java.lang.Boolean urlEncode)
Resolve link for rendering.-
Methods inherited from class com.vladsch.flexmark.html.NodeRendererSubContext
doNotRenderLinks, doNotRenderLinks, doRenderLinks, flushTo, flushTo, getDoNotRenderLinksNesting, getHtmlWriter, isDoNotRenderLinks
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vladsch.flexmark.html.renderer.LinkResolverContext
resolveLink
-
Methods inherited from interface com.vladsch.flexmark.html.renderer.NodeRendererContext
doNotRenderLinks, doNotRenderLinks, doRenderLinks, getHtmlWriter, isDoNotRenderLinks
-
-
-
-
Field Detail
-
document
private Document document
-
renderers
private java.util.Map<java.lang.Class<?>,NodeRenderingHandlerWrapper> renderers
-
phasedRenderers
private java.util.List<PhasedNodeRenderer> phasedRenderers
-
myLinkResolvers
private LinkResolver[] myLinkResolvers
-
renderingPhases
private java.util.Set<RenderingPhase> renderingPhases
-
options
private DataHolder options
-
phase
private RenderingPhase phase
-
htmlIdGenerator
HtmlIdGenerator htmlIdGenerator
-
resolvedLinkMap
private java.util.HashMap<LinkType,java.util.HashMap<java.lang.String,ResolvedLink>> resolvedLinkMap
-
attributeProviders
private AttributeProvider[] attributeProviders
-
-
Constructor Detail
-
MainNodeRenderer
MainNodeRenderer(DataHolder options, HtmlWriter htmlWriter, Document document)
-
-
Method Detail
-
dispose
public void dispose()
- Specified by:
dispose
in interfaceDisposable
-
getCurrentNode
@NotNull public @NotNull Node getCurrentNode()
- Specified by:
getCurrentNode
in interfaceLinkResolverContext
- Returns:
- the current node being rendered
-
resolveLink
@NotNull public @NotNull ResolvedLink resolveLink(@NotNull @NotNull LinkType linkType, @NotNull @NotNull java.lang.CharSequence url, Attributes attributes, java.lang.Boolean urlEncode)
Description copied from interface:LinkResolverContext
Resolve link for rendering. Link Resolvers are going to be called until one returns ResolvedLink with getStatus() != LinkStatus.UnknownA resolver can replace the url but not change the status letting downstream resolvers handle the rest. This is useful when a resolver does partial processing like macro expansion but does not know how to handle the rest.
Core processing will simply pass the link as is. It is up to extension LinkResolvers and AttributeProviders to make sense of the link and applicable attributes based on status.
- Specified by:
resolveLink
in interfaceLinkResolverContext
- Parameters:
linkType
- type of link being rendered. Core defined links are Link, Image. Extensions can define their ownurl
- link url textattributes
- link attributesurlEncode
- whether the link should be url encoded, if null then the value ofHtmlRenderer.PERCENT_ENCODE_URLS
will be used to determine whether the resolved URL is to be encoded.- Returns:
- resolved link url for this link and its resolved status
-
getNodeId
public java.lang.String getNodeId(@NotNull @NotNull Node node)
Description copied from interface:NodeRendererContext
Get the id attribute for the given node.- Specified by:
getNodeId
in interfaceNodeRendererContext
- Parameters:
node
- node for which to get an id, depends on theHtmlIdGenerator
assigned for the context. Default generator only creates ids forHeading
nodes or custom nodes that implementAnchorRefTarget
interface.- Returns:
- id string or null
-
getOptions
@NotNull public @NotNull DataHolder getOptions()
Description copied from interface:LinkResolverContext
Get the current rendering contextDataHolder
. These are the options passed or set on theHtmlRenderer.builder()
or passed toHtmlRenderer.builder(DataHolder)
. To get the document options you should useLinkResolverContext.getDocument()
as the data holder.- Specified by:
getOptions
in interfaceLinkResolverBasicContext
- Specified by:
getOptions
in interfaceLinkResolverContext
- Returns:
- the current renderer options
DataHolder
-
getHtmlOptions
@NotNull public @NotNull HtmlRendererOptions getHtmlOptions()
- Specified by:
getHtmlOptions
in interfaceNodeRendererContext
- Returns:
- the
HtmlRendererOptions
for the context.
-
getDocument
@NotNull public @NotNull Document getDocument()
- Specified by:
getDocument
in interfaceLinkResolverBasicContext
- Specified by:
getDocument
in interfaceLinkResolverContext
- Returns:
- the
Document
node of the current context
-
getRenderingPhase
@NotNull public @NotNull RenderingPhase getRenderingPhase()
- Specified by:
getRenderingPhase
in interfaceNodeRendererContext
- Returns:
- current rendering phase
-
encodeUrl
@NotNull public @NotNull java.lang.String encodeUrl(@NotNull @NotNull java.lang.CharSequence url)
- Specified by:
encodeUrl
in interfaceLinkResolverContext
- Parameters:
url
- to be encoded- Returns:
- an encoded URL (depending on the configuration)
-
extendRenderingNodeAttributes
@NotNull public @NotNull MutableAttributes extendRenderingNodeAttributes(@NotNull @NotNull AttributablePart part, Attributes attributes)
Description copied from interface:NodeRendererContext
Extend the attributes by extensions for the node being currently rendered.- Specified by:
extendRenderingNodeAttributes
in interfaceNodeRendererContext
- Parameters:
part
- the tag of the node being rendered, some nodes render multiple tags with attributesattributes
- the attributes that were calculated by the renderer or null, these may be modified. To preserve originals pass a copy.- Returns:
- the extended attributes with added/updated/removed entries
-
extendRenderingNodeAttributes
@NotNull public @NotNull MutableAttributes extendRenderingNodeAttributes(@NotNull @NotNull Node node, @NotNull @NotNull AttributablePart part, Attributes attributes)
Description copied from interface:NodeRendererContext
Extend the attributes by extensions for the node being currently rendered.- Specified by:
extendRenderingNodeAttributes
in interfaceNodeRendererContext
- Parameters:
node
- node for which to get attributespart
- the tag of the node being rendered, some nodes render multiple tags with attributesattributes
- the attributes that were calculated by the renderer or null, these may be modified. To preserve originals pass a copy.- Returns:
- the extended attributes with added/updated/removed entries
-
render
public void render(@NotNull @NotNull Node node)
Description copied from interface:LinkResolverContext
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.- Specified by:
render
in interfaceLinkResolverContext
- Parameters:
node
- the node to render
-
delegateRender
public void delegateRender()
Description copied from interface:NodeRendererContext
pass node rendering to previously registered handler- Specified by:
delegateRender
in interfaceNodeRendererContext
-
renderByPreviousHandler
void renderByPreviousHandler(NodeRendererSubContext subContext)
-
getSubContext
@NotNull public @NotNull NodeRendererContext getSubContext(boolean inheritIndent)
Description copied from interface:NodeRendererContext
Creates a child rendering context that can be used to collect rendered html text. The child context inherits everything but the HtmlRenderer, renderedNode, renderingHandler and doNotRenderLinksNesting from the parent.- Specified by:
getSubContext
in interfaceNodeRendererContext
- Parameters:
inheritIndent
- whether the html writer of the sub-context should inherit the current context's indentation level or start with 0 indentation- Returns:
- a new rendering context with a given appendable for its output
-
getDelegatedSubContext
@NotNull public @NotNull NodeRendererContext getDelegatedSubContext(boolean inheritIndent)
Description copied from interface:NodeRendererContext
Creates a child rendering context that can be used to collect rendered html text of the previously registered node renderer. The child context inherits everything but the HtmlRenderer and doNotRenderLinksNesting from the parent.- Specified by:
getDelegatedSubContext
in interfaceNodeRendererContext
- Parameters:
inheritIndent
- whether the html writer of the sub-context should inherit the current context's indentation level or start with 0 indentation- Returns:
- a new rendering context with a given appendable for its output
-
renderNode
void renderNode(Node node, NodeRendererSubContext subContext)
-
renderChildren
public void renderChildren(@NotNull @NotNull Node parent)
Description copied from interface:LinkResolverContext
Render the children of the node, used by custom renderers- Specified by:
renderChildren
in interfaceLinkResolverContext
- Parameters:
parent
- node the children of which are to be rendered
-
renderChildrenNode
protected void renderChildrenNode(Node parent, NodeRendererSubContext subContext)
-
-