Class Formatter.MainNodeFormatter.SubNodeFormatter
- All Implemented Interfaces:
ExplicitAttributeIdProvider
,NodeFormatterContext
,TranslationContext
,LinkResolverBasicContext
,LinkResolverContext
,NodeContext<Node,
NodeFormatterContext>
- Enclosing class:
Formatter.MainNodeFormatter
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final FormatterOptions
private final Formatter.MainNodeFormatter
private final DataHolder
Fields inherited from class com.vladsch.flexmark.formatter.NodeFormatterSubContext
markdown, rendererIndex, rendererList, renderingNode
-
Constructor Summary
ConstructorsConstructorDescriptionSubNodeFormatter
(Formatter.MainNodeFormatter mainNodeRenderer, MarkdownWriter out, @Nullable DataHolder options) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addExplicitId
(@NotNull Node node, @Nullable String id, @NotNull NodeFormatterContext context, @NotNull MarkdownWriter markdown) Used by AttributesExtension to insert attributes for headings during mergevoid
customPlaceholderFormat
(@NotNull TranslationPlaceholderGenerator generator, @NotNull TranslatingSpanRender render) Temporarily change the format for placeholdersvoid
pass node rendering to previously registered handler@NotNull String
encodeUrl
(@NotNull CharSequence url) @NotNull BasedSequence
@NotNull CharPredicate
@NotNull Node
@NotNull Document
@NotNull FormatterOptions
@NotNull FormattingPhase
@NotNull MarkdownWriter
@NotNull DataHolder
Get the current rendering contextDataHolder
.@NotNull RenderPurpose
Get the reason this format rendering is being performed@NotNull NodeFormatterContext
Creates a child rendering context that can be used to collect rendered html text.@NotNull NodeFormatterContext
getSubContext
(@Nullable DataHolder options) Creates a child rendering context that can be used to collect rendered html text.@NotNull NodeFormatterContext
getSubContext
(@Nullable DataHolder options, @NotNull ISequenceBuilder<?, ?> builder) Creates a child rendering context that can be used to collect rendered html text.@NotNull TrackedOffsetList
Sub-context does not have offset tracking@NotNull BasedSequence
NOTE: parser can only use a contiguous sequence, not segmented.@NotNull MutableDataHolder
Get MutableDataHolder for storing this translation run values across render purpose phasesboolean
boolean
boolean
Returns false if special translation functions are no-opsnodesOfType
(@NotNull Class<?>[] classes) Get iterable of nodes of given types, in order of their appearance in the document tree, depth first traversal.nodesOfType
(@NotNull Collection<Class<?>> classes) void
nonTranslatingSpan
(@NotNull TranslatingSpanRender render) Separate non-translation span.void
postProcessNonTranslating
(@NotNull Function<String, CharSequence> postProcessor, @NotNull Runnable scope) <T> T
postProcessNonTranslating
(@NotNull Function<String, CharSequence> postProcessor, @NotNull Supplier<T> scope) void
Render the specified node and its children using the configured renderers.void
renderChildren
(@NotNull Node parent) Render the children of the node, used by custom renderers@NotNull ResolvedLink
resolveLink
(@NotNull LinkType linkType, @NotNull CharSequence url, Attributes attributes, Boolean urlEncode) Resolve link for rendering.@NotNull ResolvedLink
resolveLink
(@NotNull LinkType linkType, @NotNull CharSequence url, Boolean urlEncode) Resolve link for rendering.reversedNodesOfType
(@NotNull Class<?>[] classes) Get iterable of nodes of given types, in reverse order of their appearance in the document tree, depth first traversal.reversedNodesOfType
(@NotNull Collection<Class<?>> classes) @NotNull CharSequence
transformAnchorRef
(@NotNull CharSequence pageRef, @NotNull CharSequence anchorRef) DuringRenderPurpose.TRANSLATION_SPANS
this converts anchorRef to ordinal placeholder id DuringRenderPurpose.TRANSLATED_SPANS
this returns the ordinal placeholder DuringRenderPurpose.TRANSLATED
this returns new anchorRef for the AnchorRefTarget original was referring to@NotNull CharSequence
transformNonTranslating
(CharSequence prefix, @NotNull CharSequence nonTranslatingText, CharSequence suffix, CharSequence suffix2) Transform non-translating text@NotNull CharSequence
transformTranslating
(CharSequence prefix, @NotNull CharSequence translatingText, CharSequence suffix, CharSequence suffix2) Transform translating text but which is contextually isolated from the text block in which it is located ie.void
translatingRefTargetSpan
(@Nullable Node target, @NotNull TranslatingSpanRender render) Separate translation span which is also a ref targetvoid
translatingSpan
(@NotNull TranslatingSpanRender render) Separate translation span.Methods inherited from class com.vladsch.flexmark.formatter.NodeFormatterSubContext
flushTo, flushTo, getRenderingNode, setRenderingNode
-
Field Details
-
myMainNodeRenderer
-
myOptions
-
myFormatterOptions
-
-
Constructor Details
-
SubNodeFormatter
public SubNodeFormatter(Formatter.MainNodeFormatter mainNodeRenderer, MarkdownWriter out, @Nullable @Nullable DataHolder options)
-
-
Method Details
-
getTranslationStore
Description copied from interface:TranslationContext
Get MutableDataHolder for storing this translation run values across render purpose phases- Specified by:
getTranslationStore
in interfaceTranslationContext
-
nodesOfType
@NotNull public final @NotNull Iterable<? extends Node> nodesOfType(@NotNull @NotNull Class<?>[] classes) Description copied from interface:NodeFormatterContext
Get iterable of nodes of given types, in order of their appearance in the document tree, depth first traversal. Only node classes returned byNodeFormatter.getNodeClasses()
of all loaded extensions will be available to formatters.CoreNodeFormatter
registersRefNode
ifFormatter.REFERENCE_SORT
is set toElementPlacementSort.SORT_UNUSED_LAST
so that- Specified by:
nodesOfType
in interfaceNodeFormatterContext
- Parameters:
classes
- node classes to return- Returns:
- iterable
-
nodesOfType
@NotNull public final @NotNull Iterable<? extends Node> nodesOfType(@NotNull @NotNull Collection<Class<?>> classes) - Specified by:
nodesOfType
in interfaceNodeFormatterContext
-
reversedNodesOfType
@NotNull public final @NotNull Iterable<? extends Node> reversedNodesOfType(@NotNull @NotNull Class<?>[] classes) Description copied from interface:NodeFormatterContext
Get iterable of nodes of given types, in reverse order of their appearance in the document tree, depth first traversal. Only node classes returned byNodeFormatter.getNodeClasses()
of all loaded extensions will be available to formatters.CoreNodeFormatter
registersRefNode
ifFormatter.REFERENCE_SORT
is set toElementPlacementSort.SORT_UNUSED_LAST
so that- Specified by:
reversedNodesOfType
in interfaceNodeFormatterContext
- Parameters:
classes
- node classes to return- Returns:
- iterable
-
reversedNodesOfType
@NotNull public final @NotNull Iterable<? extends Node> reversedNodesOfType(@NotNull @NotNull Collection<Class<?>> classes) - Specified by:
reversedNodesOfType
in interfaceNodeFormatterContext
-
getOptions
Description copied from interface:NodeFormatterContext
Get the current rendering contextDataHolder
. These are the options passed or set on theFormatter.builder()
or passed toFormatter.builder(DataHolder)
. To get the document options you should useNodeFormatterContext.getDocument()
as the data holder.- Specified by:
getOptions
in interfaceLinkResolverBasicContext
- Specified by:
getOptions
in interfaceLinkResolverContext
- Specified by:
getOptions
in interfaceNodeContext<Node,
NodeFormatterContext> - Specified by:
getOptions
in interfaceNodeFormatterContext
- Returns:
- the current renderer options
DataHolder
-
getFormatterOptions
- Specified by:
getFormatterOptions
in interfaceNodeFormatterContext
- Returns:
- the
FormatterOptions
for the context.
-
getDocument
- Specified by:
getDocument
in interfaceLinkResolverBasicContext
- Specified by:
getDocument
in interfaceLinkResolverContext
- Specified by:
getDocument
in interfaceNodeFormatterContext
- Returns:
- the
Document
node of the current context
-
getBlockQuoteLikePrefixPredicate
- Specified by:
getBlockQuoteLikePrefixPredicate
in interfaceNodeFormatterContext
- Returns:
- predicate for prefix chars which compact like block quote prefix char
-
getBlockQuoteLikePrefixChars
- Specified by:
getBlockQuoteLikePrefixChars
in interfaceNodeFormatterContext
- Returns:
- char sequence of all prefix chars which compact like block quote prefix char
-
getTrackedOffsets
Sub-context does not have offset tracking- Specified by:
getTrackedOffsets
in interfaceNodeFormatterContext
- Returns:
- empty lise
-
isRestoreTrackedSpaces
public boolean isRestoreTrackedSpaces()- Specified by:
isRestoreTrackedSpaces
in interfaceNodeFormatterContext
-
getTrackedSequence
Description copied from interface:NodeFormatterContext
NOTE: parser can only use a contiguous sequence, not segmented. Therefore, the AST offsets and base sequence from AST nodes has always an index into sequence equal to the offset. This sequence is set to notBasedSequence.NULL
when the format sequence used for tracked offsets is not contiguous and TrackedOffset.offset is an offset from this sequence and need to be converted to index into this sequence to be used as an offset into AST sequence for offset conversion- Specified by:
getTrackedSequence
in interfaceNodeFormatterContext
- Returns:
- original sequence used for tracked offsets.
-
getFormattingPhase
- Specified by:
getFormattingPhase
in interfaceNodeFormatterContext
- Returns:
- current rendering phase
-
render
Description copied from interface:NodeFormatterContext
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
- Specified by:
render
in interfaceNodeFormatterContext
- Parameters:
node
- the node to render
-
getCurrentNode
- Specified by:
getCurrentNode
in interfaceLinkResolverContext
- Specified by:
getCurrentNode
in interfaceNodeContext<Node,
NodeFormatterContext> - Returns:
- the current node being rendered
-
delegateRender
public void delegateRender()Description copied from interface:NodeFormatterContext
pass node rendering to previously registered handler- Specified by:
delegateRender
in interfaceNodeFormatterContext
-
getSubContext
Description copied from interface:NodeContext
Creates a child rendering context that can be used to collect rendered html text. The child context inherits everything but the HtmlRenderer and doNotRenderLinksNesting from the parent.- Specified by:
getSubContext
in interfaceNodeContext<Node,
NodeFormatterContext> - Returns:
- a new rendering context with a given appendable for its output
-
getSubContext
Description copied from interface:NodeContext
Creates a child rendering context that can be used to collect rendered html text. The child context inherits everything but the HtmlRenderer and doNotRenderLinksNesting from the parent.- Specified by:
getSubContext
in interfaceNodeContext<Node,
NodeFormatterContext> - Parameters:
options
- options to use for the context (only options which do not affect the context construction will be used)- Returns:
- a new rendering context with a given appendable for its output
-
getSubContext
@NotNull public @NotNull NodeFormatterContext getSubContext(@Nullable @Nullable DataHolder options, @NotNull @NotNull ISequenceBuilder<?, ?> builder) Description copied from interface:NodeContext
Creates a child rendering context that can be used to collect rendered html text. The child context inherits everything but the HtmlRenderer and doNotRenderLinksNesting from the parent.- Specified by:
getSubContext
in interfaceNodeContext<Node,
NodeFormatterContext> - Parameters:
options
- options to use for the context (only options which do not affect the context construction will be used)builder
- sequence builder to user for appended text for tracking original base offsets- Returns:
- a new rendering context with a given appendable for its output
-
renderChildren
Description copied from interface:NodeFormatterContext
Render the children of the node, used by custom renderers- Specified by:
renderChildren
in interfaceLinkResolverContext
- Specified by:
renderChildren
in interfaceNodeFormatterContext
- Parameters:
parent
- node the children of which are to be rendered
-
getMarkdown
- Specified by:
getMarkdown
in interfaceNodeFormatterContext
- Overrides:
getMarkdown
in classNodeFormatterSubContext
- Returns:
- the HTML writer to use
-
getRenderPurpose
Description copied from interface:TranslationContext
Get the reason this format rendering is being performed- Specified by:
getRenderPurpose
in interfaceTranslationContext
- Returns:
- RenderPurpose for current rendering
-
isTransformingText
public boolean isTransformingText()Description copied from interface:TranslationContext
Returns false if special translation functions are no-opsDuring
RenderPurpose.TRANSLATION_SPANS
this is true DuringRenderPurpose.TRANSLATED_SPANS
this is true DuringRenderPurpose.TRANSLATED
this is true- Specified by:
isTransformingText
in interfaceTranslationContext
- Returns:
- true if need to call translation related functions
-
transformNonTranslating
@NotNull public @NotNull CharSequence transformNonTranslating(CharSequence prefix, @NotNull @NotNull CharSequence nonTranslatingText, CharSequence suffix, CharSequence suffix2) Description copied from interface:TranslationContext
Transform non-translating textDuring
RenderPurpose.TRANSLATION_SPANS
this converts text to non-translating placeholder based on ordinal id DuringRenderPurpose.TRANSLATED_SPANS
this returns the non-translating placeholder based on ordinal id DuringRenderPurpose.TRANSLATED
this returns the original non-translating text for the nonTranslatingText (placeholder)- Specified by:
transformNonTranslating
in interfaceTranslationContext
- Parameters:
prefix
- prefix to use on non-translating placeholder so it is interpreted as a proper element during parsingnonTranslatingText
- non-rendering text of the node (content will depend on translation phase)suffix
- suffix to use on non-translating placeholder so it is interpreted as a proper element during parsingsuffix2
- suffix to use on non-translating placeholder so it is interpreted as a proper element during parsing- Returns:
- text to be used in rendering for this phase
-
transformTranslating
@NotNull public @NotNull CharSequence transformTranslating(CharSequence prefix, @NotNull @NotNull CharSequence translatingText, CharSequence suffix, CharSequence suffix2) Description copied from interface:TranslationContext
Transform translating text but which is contextually isolated from the text block in which it is located ie. link reference or image referenceDuring
RenderPurpose.TRANSLATION_SPANS
this converts text to non-translating placeholder based on ordinal id and adds it to translation snippets DuringRenderPurpose.TRANSLATED_SPANS
this returns the non-translating placeholder based on ordinal id DuringRenderPurpose.TRANSLATED
this returns the translated text for the translatingText (placeholder)- Specified by:
transformTranslating
in interfaceTranslationContext
- Parameters:
prefix
- prefix to use on non-translating placeholder so it is interpreted as a proper element during parsingtranslatingText
- translating but isolated text of the node (content will depend on translation phase)suffix
- suffix to use on non-translating placeholder so it is interpreted as a proper element during parsingsuffix2
- suffix to use on non-translating placeholder so it is interpreted as a proper element during parsing- Returns:
- text to be used in rendering for this phase
-
transformAnchorRef
@NotNull public @NotNull CharSequence transformAnchorRef(@NotNull @NotNull CharSequence pageRef, @NotNull @NotNull CharSequence anchorRef) Description copied from interface:TranslationContext
DuringRenderPurpose.TRANSLATION_SPANS
this converts anchorRef to ordinal placeholder id DuringRenderPurpose.TRANSLATED_SPANS
this returns the ordinal placeholder DuringRenderPurpose.TRANSLATED
this returns new anchorRef for the AnchorRefTarget original was referring to- Specified by:
transformAnchorRef
in interfaceTranslationContext
- Parameters:
pageRef
- url part without the anchor ref to resolve referenceanchorRef
- anchor ref- Returns:
- anchorRef for the phase to be used for rendering
-
translatingSpan
Description copied from interface:TranslationContext
Separate translation span. Will generate a paragraph of text which should be translated as one pieceDuring
RenderPurpose.TRANSLATION_SPANS
this adds the generated output to translation spans DuringRenderPurpose.TRANSLATED_SPANS
output from renderer is suppressed, instead outputs corresponding translated span DuringRenderPurpose.TRANSLATED
calls render- Specified by:
translatingSpan
in interfaceTranslationContext
-
nonTranslatingSpan
Description copied from interface:TranslationContext
Separate non-translation span. Will generate a paragraph of text which will not be translatedDuring
RenderPurpose.TRANSLATION_SPANS
this adds the generated output to translation spans DuringRenderPurpose.TRANSLATED_SPANS
output from renderer is suppressed, instead outputs corresponding translated span DuringRenderPurpose.TRANSLATED
calls render- Specified by:
nonTranslatingSpan
in interfaceTranslationContext
-
translatingRefTargetSpan
public void translatingRefTargetSpan(@Nullable @Nullable Node target, @NotNull @NotNull TranslatingSpanRender render) Description copied from interface:TranslationContext
Separate translation span which is also a ref target- Specified by:
translatingRefTargetSpan
in interfaceTranslationContext
- Parameters:
target
- target node,render
-
-
customPlaceholderFormat
public void customPlaceholderFormat(@NotNull @NotNull TranslationPlaceholderGenerator generator, @NotNull @NotNull TranslatingSpanRender render) Description copied from interface:TranslationContext
Temporarily change the format for placeholders- Specified by:
customPlaceholderFormat
in interfaceTranslationContext
- Parameters:
generator
- placeholder generatorrender
- render which will be used with the custom generator
-
encodeUrl
- Specified by:
encodeUrl
in interfaceLinkResolverContext
- Parameters:
url
- to be encoded- Returns:
- an encoded URL (depending on the configuration)
-
resolveLink
@NotNull public @NotNull ResolvedLink resolveLink(@NotNull @NotNull LinkType linkType, @NotNull @NotNull CharSequence url, 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 texturlEncode
- 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
-
resolveLink
@NotNull public @NotNull ResolvedLink resolveLink(@NotNull @NotNull LinkType linkType, @NotNull @NotNull CharSequence url, Attributes attributes, 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
-
postProcessNonTranslating
public void postProcessNonTranslating(@NotNull @NotNull Function<String, CharSequence> postProcessor, @NotNull @NotNull Runnable scope) - Specified by:
postProcessNonTranslating
in interfaceTranslationContext
- Parameters:
postProcessor
- id post processor for TRANSLATED purposescope
- code to which the post processor applies
-
postProcessNonTranslating
@NotNull public <T> T postProcessNonTranslating(@NotNull @NotNull Function<String, CharSequence> postProcessor, @NotNull @NotNull Supplier<T> scope) - Specified by:
postProcessNonTranslating
in interfaceTranslationContext
- Parameters:
postProcessor
- id post processor for TRANSLATED purposescope
- code to which the post processor applies
-
isPostProcessingNonTranslating
public boolean isPostProcessingNonTranslating()- Specified by:
isPostProcessingNonTranslating
in interfaceTranslationContext
- Returns:
- true if non-translating post processor is set
-
getMergeContext
- Specified by:
getMergeContext
in interfaceTranslationContext
-
addExplicitId
public void addExplicitId(@NotNull @NotNull Node node, @Nullable @Nullable String id, @NotNull @NotNull NodeFormatterContext context, @NotNull @NotNull MarkdownWriter markdown) Description copied from interface:ExplicitAttributeIdProvider
Used by AttributesExtension to insert attributes for headings during merge- Specified by:
addExplicitId
in interfaceExplicitAttributeIdProvider
- Parameters:
node
- nodeid
- explicit idcontext
- contextmarkdown
- markdown writer
-
getIdGenerator
- Specified by:
getIdGenerator
in interfaceTranslationContext
-