Class Formatter.MainNodeFormatter.SubNodeFormatter
- java.lang.Object
-
- com.vladsch.flexmark.formatter.NodeFormatterSubContext
-
- com.vladsch.flexmark.formatter.Formatter.MainNodeFormatter.SubNodeFormatter
-
- All Implemented Interfaces:
ExplicitAttributeIdProvider,NodeFormatterContext,TranslationContext,LinkResolverBasicContext,LinkResolverContext,NodeContext<Node,NodeFormatterContext>
- Enclosing class:
- Formatter.MainNodeFormatter
private class Formatter.MainNodeFormatter.SubNodeFormatter extends NodeFormatterSubContext implements NodeFormatterContext
-
-
Field Summary
Fields Modifier and Type Field Description private FormatterOptionsmyFormatterOptionsprivate Formatter.MainNodeFormattermyMainNodeRendererprivate DataHoldermyOptions-
Fields inherited from class com.vladsch.flexmark.formatter.NodeFormatterSubContext
markdown, rendererIndex, rendererList, renderingNode
-
-
Constructor Summary
Constructors Constructor Description SubNodeFormatter(Formatter.MainNodeFormatter mainNodeRenderer, MarkdownWriter out, @Nullable DataHolder options)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddExplicitId(@NotNull Node node, @Nullable java.lang.String id, @NotNull NodeFormatterContext context, @NotNull MarkdownWriter markdown)Used by AttributesExtension to insert attributes for headings during mergevoidcustomPlaceholderFormat(@NotNull TranslationPlaceholderGenerator generator, @NotNull TranslatingSpanRender render)Temporarily change the format for placeholdersvoiddelegateRender()pass node rendering to previously registered handler@NotNull java.lang.StringencodeUrl(@NotNull java.lang.CharSequence url)@NotNull BasedSequencegetBlockQuoteLikePrefixChars()@NotNull CharPredicategetBlockQuoteLikePrefixPredicate()@NotNull NodegetCurrentNode()@NotNull DocumentgetDocument()@NotNull FormatterOptionsgetFormatterOptions()@NotNull FormattingPhasegetFormattingPhase()HtmlIdGeneratorgetIdGenerator()@NotNull MarkdownWritergetMarkdown()MergeContextgetMergeContext()@NotNull DataHoldergetOptions()Get the current rendering contextDataHolder.@NotNull RenderPurposegetRenderPurpose()Get the reason this format rendering is being performed@NotNull NodeFormatterContextgetSubContext()Creates a child rendering context that can be used to collect rendered html text.@NotNull NodeFormatterContextgetSubContext(@Nullable DataHolder options)Creates a child rendering context that can be used to collect rendered html text.@NotNull NodeFormatterContextgetSubContext(@Nullable DataHolder options, @NotNull ISequenceBuilder<?,?> builder)Creates a child rendering context that can be used to collect rendered html text.@NotNull TrackedOffsetListgetTrackedOffsets()Sub-context does not have offset tracking@NotNull BasedSequencegetTrackedSequence()NOTE: parser can only use a contiguous sequence, not segmented.@NotNull MutableDataHoldergetTranslationStore()Get MutableDataHolder for storing this translation run values across render purpose phasesbooleanisPostProcessingNonTranslating()booleanisRestoreTrackedSpaces()booleanisTransformingText()Returns false if special translation functions are no-ops@NotNull java.lang.Iterable<? extends Node>nodesOfType(@NotNull java.lang.Class<?>[] classes)Get iterable of nodes of given types, in order of their appearance in the document tree, depth first traversal.@NotNull java.lang.Iterable<? extends Node>nodesOfType(@NotNull java.util.Collection<java.lang.Class<?>> classes)voidnonTranslatingSpan(@NotNull TranslatingSpanRender render)Separate non-translation span.voidpostProcessNonTranslating(@NotNull java.util.function.Function<java.lang.String,java.lang.CharSequence> postProcessor, @NotNull java.lang.Runnable scope)<T> TpostProcessNonTranslating(@NotNull java.util.function.Function<java.lang.String,java.lang.CharSequence> postProcessor, @NotNull java.util.function.Supplier<T> scope)voidrender(@NotNull Node node)Render the specified node and its children using the configured renderers.voidrenderChildren(@NotNull Node parent)Render the children of the node, used by custom renderers@NotNull ResolvedLinkresolveLink(@NotNull LinkType linkType, @NotNull java.lang.CharSequence url, Attributes attributes, java.lang.Boolean urlEncode)Resolve link for rendering.@NotNull ResolvedLinkresolveLink(@NotNull LinkType linkType, @NotNull java.lang.CharSequence url, java.lang.Boolean urlEncode)Resolve link for rendering.@NotNull java.lang.Iterable<? extends Node>reversedNodesOfType(@NotNull java.lang.Class<?>[] classes)Get iterable of nodes of given types, in reverse order of their appearance in the document tree, depth first traversal.@NotNull java.lang.Iterable<? extends Node>reversedNodesOfType(@NotNull java.util.Collection<java.lang.Class<?>> classes)@NotNull java.lang.CharSequencetransformAnchorRef(@NotNull java.lang.CharSequence pageRef, @NotNull java.lang.CharSequence anchorRef)DuringRenderPurpose.TRANSLATION_SPANSthis converts anchorRef to ordinal placeholder id DuringRenderPurpose.TRANSLATED_SPANSthis returns the ordinal placeholder DuringRenderPurpose.TRANSLATEDthis returns new anchorRef for the AnchorRefTarget original was referring to@NotNull java.lang.CharSequencetransformNonTranslating(java.lang.CharSequence prefix, @NotNull java.lang.CharSequence nonTranslatingText, java.lang.CharSequence suffix, java.lang.CharSequence suffix2)Transform non-translating text@NotNull java.lang.CharSequencetransformTranslating(java.lang.CharSequence prefix, @NotNull java.lang.CharSequence translatingText, java.lang.CharSequence suffix, java.lang.CharSequence suffix2)Transform translating text but which is contextually isolated from the text block in which it is located ie.voidtranslatingRefTargetSpan(@Nullable Node target, @NotNull TranslatingSpanRender render)Separate translation span which is also a ref targetvoidtranslatingSpan(@NotNull TranslatingSpanRender render)Separate translation span.-
Methods inherited from class com.vladsch.flexmark.formatter.NodeFormatterSubContext
flushTo, flushTo, getRenderingNode, setRenderingNode
-
-
-
-
Field Detail
-
myMainNodeRenderer
private final Formatter.MainNodeFormatter myMainNodeRenderer
-
myOptions
private final DataHolder myOptions
-
myFormatterOptions
private final FormatterOptions myFormatterOptions
-
-
Constructor Detail
-
SubNodeFormatter
public SubNodeFormatter(Formatter.MainNodeFormatter mainNodeRenderer, MarkdownWriter out, @Nullable @Nullable DataHolder options)
-
-
Method Detail
-
getTranslationStore
@NotNull public @NotNull MutableDataHolder getTranslationStore()
Description copied from interface:TranslationContextGet MutableDataHolder for storing this translation run values across render purpose phases- Specified by:
getTranslationStorein interfaceTranslationContext
-
nodesOfType
@NotNull public final @NotNull java.lang.Iterable<? extends Node> nodesOfType(@NotNull @NotNull java.lang.Class<?>[] classes)
Description copied from interface:NodeFormatterContextGet 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.CoreNodeFormatterregistersRefNodeifFormatter.REFERENCE_SORTis set toElementPlacementSort.SORT_UNUSED_LASTso that- Specified by:
nodesOfTypein interfaceNodeFormatterContext- Parameters:
classes- node classes to return- Returns:
- iterable
-
nodesOfType
@NotNull public final @NotNull java.lang.Iterable<? extends Node> nodesOfType(@NotNull @NotNull java.util.Collection<java.lang.Class<?>> classes)
- Specified by:
nodesOfTypein interfaceNodeFormatterContext
-
reversedNodesOfType
@NotNull public final @NotNull java.lang.Iterable<? extends Node> reversedNodesOfType(@NotNull @NotNull java.lang.Class<?>[] classes)
Description copied from interface:NodeFormatterContextGet 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.CoreNodeFormatterregistersRefNodeifFormatter.REFERENCE_SORTis set toElementPlacementSort.SORT_UNUSED_LASTso that- Specified by:
reversedNodesOfTypein interfaceNodeFormatterContext- Parameters:
classes- node classes to return- Returns:
- iterable
-
reversedNodesOfType
@NotNull public final @NotNull java.lang.Iterable<? extends Node> reversedNodesOfType(@NotNull @NotNull java.util.Collection<java.lang.Class<?>> classes)
- Specified by:
reversedNodesOfTypein interfaceNodeFormatterContext
-
getOptions
@NotNull public @NotNull DataHolder getOptions()
Description copied from interface:NodeFormatterContextGet 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:
getOptionsin interfaceLinkResolverBasicContext- Specified by:
getOptionsin interfaceLinkResolverContext- Specified by:
getOptionsin interfaceNodeContext<Node,NodeFormatterContext>- Specified by:
getOptionsin interfaceNodeFormatterContext- Returns:
- the current renderer options
DataHolder
-
getFormatterOptions
@NotNull public @NotNull FormatterOptions getFormatterOptions()
- Specified by:
getFormatterOptionsin interfaceNodeFormatterContext- Returns:
- the
FormatterOptionsfor the context.
-
getDocument
@NotNull public @NotNull Document getDocument()
- Specified by:
getDocumentin interfaceLinkResolverBasicContext- Specified by:
getDocumentin interfaceLinkResolverContext- Specified by:
getDocumentin interfaceNodeFormatterContext- Returns:
- the
Documentnode of the current context
-
getBlockQuoteLikePrefixPredicate
@NotNull public @NotNull CharPredicate getBlockQuoteLikePrefixPredicate()
- Specified by:
getBlockQuoteLikePrefixPredicatein interfaceNodeFormatterContext- Returns:
- predicate for prefix chars which compact like block quote prefix char
-
getBlockQuoteLikePrefixChars
@NotNull public @NotNull BasedSequence getBlockQuoteLikePrefixChars()
- Specified by:
getBlockQuoteLikePrefixCharsin interfaceNodeFormatterContext- Returns:
- char sequence of all prefix chars which compact like block quote prefix char
-
getTrackedOffsets
@NotNull public @NotNull TrackedOffsetList getTrackedOffsets()
Sub-context does not have offset tracking- Specified by:
getTrackedOffsetsin interfaceNodeFormatterContext- Returns:
- empty lise
-
isRestoreTrackedSpaces
public boolean isRestoreTrackedSpaces()
- Specified by:
isRestoreTrackedSpacesin interfaceNodeFormatterContext
-
getTrackedSequence
@NotNull public @NotNull BasedSequence getTrackedSequence()
Description copied from interface:NodeFormatterContextNOTE: 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.NULLwhen 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:
getTrackedSequencein interfaceNodeFormatterContext- Returns:
- original sequence used for tracked offsets.
-
getFormattingPhase
@NotNull public @NotNull FormattingPhase getFormattingPhase()
- Specified by:
getFormattingPhasein interfaceNodeFormatterContext- Returns:
- current rendering phase
-
render
public void render(@NotNull @NotNull Node node)Description copied from interface:NodeFormatterContextRender 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:
renderin interfaceLinkResolverContext- Specified by:
renderin interfaceNodeFormatterContext- Parameters:
node- the node to render
-
getCurrentNode
@NotNull public @NotNull Node getCurrentNode()
- Specified by:
getCurrentNodein interfaceLinkResolverContext- Specified by:
getCurrentNodein interfaceNodeContext<Node,NodeFormatterContext>- Returns:
- the current node being rendered
-
delegateRender
public void delegateRender()
Description copied from interface:NodeFormatterContextpass node rendering to previously registered handler- Specified by:
delegateRenderin interfaceNodeFormatterContext
-
getSubContext
@NotNull public @NotNull NodeFormatterContext getSubContext()
Description copied from interface:NodeContextCreates 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:
getSubContextin interfaceNodeContext<Node,NodeFormatterContext>- Returns:
- a new rendering context with a given appendable for its output
-
getSubContext
@NotNull public @NotNull NodeFormatterContext getSubContext(@Nullable @Nullable DataHolder options)
Description copied from interface:NodeContextCreates 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:
getSubContextin 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:NodeContextCreates 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:
getSubContextin 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
public void renderChildren(@NotNull @NotNull Node parent)Description copied from interface:NodeFormatterContextRender the children of the node, used by custom renderers- Specified by:
renderChildrenin interfaceLinkResolverContext- Specified by:
renderChildrenin interfaceNodeFormatterContext- Parameters:
parent- node the children of which are to be rendered
-
getMarkdown
@NotNull public @NotNull MarkdownWriter getMarkdown()
- Specified by:
getMarkdownin interfaceNodeFormatterContext- Overrides:
getMarkdownin classNodeFormatterSubContext- Returns:
- the HTML writer to use
-
getRenderPurpose
@NotNull public @NotNull RenderPurpose getRenderPurpose()
Description copied from interface:TranslationContextGet the reason this format rendering is being performed- Specified by:
getRenderPurposein interfaceTranslationContext- Returns:
- RenderPurpose for current rendering
-
isTransformingText
public boolean isTransformingText()
Description copied from interface:TranslationContextReturns false if special translation functions are no-opsDuring
RenderPurpose.TRANSLATION_SPANSthis is true DuringRenderPurpose.TRANSLATED_SPANSthis is true DuringRenderPurpose.TRANSLATEDthis is true- Specified by:
isTransformingTextin interfaceTranslationContext- Returns:
- true if need to call translation related functions
-
transformNonTranslating
@NotNull public @NotNull java.lang.CharSequence transformNonTranslating(java.lang.CharSequence prefix, @NotNull @NotNull java.lang.CharSequence nonTranslatingText, java.lang.CharSequence suffix, java.lang.CharSequence suffix2)Description copied from interface:TranslationContextTransform non-translating textDuring
RenderPurpose.TRANSLATION_SPANSthis converts text to non-translating placeholder based on ordinal id DuringRenderPurpose.TRANSLATED_SPANSthis returns the non-translating placeholder based on ordinal id DuringRenderPurpose.TRANSLATEDthis returns the original non-translating text for the nonTranslatingText (placeholder)- Specified by:
transformNonTranslatingin 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 java.lang.CharSequence transformTranslating(java.lang.CharSequence prefix, @NotNull @NotNull java.lang.CharSequence translatingText, java.lang.CharSequence suffix, java.lang.CharSequence suffix2)Description copied from interface:TranslationContextTransform translating text but which is contextually isolated from the text block in which it is located ie. link reference or image referenceDuring
RenderPurpose.TRANSLATION_SPANSthis converts text to non-translating placeholder based on ordinal id and adds it to translation snippets DuringRenderPurpose.TRANSLATED_SPANSthis returns the non-translating placeholder based on ordinal id DuringRenderPurpose.TRANSLATEDthis returns the translated text for the translatingText (placeholder)- Specified by:
transformTranslatingin 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 java.lang.CharSequence transformAnchorRef(@NotNull @NotNull java.lang.CharSequence pageRef, @NotNull @NotNull java.lang.CharSequence anchorRef)Description copied from interface:TranslationContextDuringRenderPurpose.TRANSLATION_SPANSthis converts anchorRef to ordinal placeholder id DuringRenderPurpose.TRANSLATED_SPANSthis returns the ordinal placeholder DuringRenderPurpose.TRANSLATEDthis returns new anchorRef for the AnchorRefTarget original was referring to- Specified by:
transformAnchorRefin 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
public void translatingSpan(@NotNull @NotNull TranslatingSpanRender render)Description copied from interface:TranslationContextSeparate translation span. Will generate a paragraph of text which should be translated as one pieceDuring
RenderPurpose.TRANSLATION_SPANSthis adds the generated output to translation spans DuringRenderPurpose.TRANSLATED_SPANSoutput from renderer is suppressed, instead outputs corresponding translated span DuringRenderPurpose.TRANSLATEDcalls render- Specified by:
translatingSpanin interfaceTranslationContext
-
nonTranslatingSpan
public void nonTranslatingSpan(@NotNull @NotNull TranslatingSpanRender render)Description copied from interface:TranslationContextSeparate non-translation span. Will generate a paragraph of text which will not be translatedDuring
RenderPurpose.TRANSLATION_SPANSthis adds the generated output to translation spans DuringRenderPurpose.TRANSLATED_SPANSoutput from renderer is suppressed, instead outputs corresponding translated span DuringRenderPurpose.TRANSLATEDcalls render- Specified by:
nonTranslatingSpanin interfaceTranslationContext
-
translatingRefTargetSpan
public void translatingRefTargetSpan(@Nullable @Nullable Node target, @NotNull @NotNull TranslatingSpanRender render)Description copied from interface:TranslationContextSeparate translation span which is also a ref target- Specified by:
translatingRefTargetSpanin interfaceTranslationContext- Parameters:
target- target node,
-
customPlaceholderFormat
public void customPlaceholderFormat(@NotNull @NotNull TranslationPlaceholderGenerator generator, @NotNull @NotNull TranslatingSpanRender render)Description copied from interface:TranslationContextTemporarily change the format for placeholders- Specified by:
customPlaceholderFormatin interfaceTranslationContext- Parameters:
generator- placeholder generatorrender- render which will be used with the custom generator
-
encodeUrl
@NotNull public @NotNull java.lang.String encodeUrl(@NotNull @NotNull java.lang.CharSequence url)- Specified by:
encodeUrlin 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 java.lang.CharSequence url, java.lang.Boolean urlEncode)
Description copied from interface:LinkResolverContextResolve 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:
resolveLinkin 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_URLSwill 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 java.lang.CharSequence url, Attributes attributes, java.lang.Boolean urlEncode)
Description copied from interface:LinkResolverContextResolve 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:
resolveLinkin 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_URLSwill 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 java.util.function.Function<java.lang.String,java.lang.CharSequence> postProcessor, @NotNull @NotNull java.lang.Runnable scope)- Specified by:
postProcessNonTranslatingin interfaceTranslationContext- Parameters:
postProcessor- id post processor for TRANSLATED purposescope- code to which the post processor applies
-
postProcessNonTranslating
@NotNull public <T> T postProcessNonTranslating(@NotNull @NotNull java.util.function.Function<java.lang.String,java.lang.CharSequence> postProcessor, @NotNull @NotNull java.util.function.Supplier<T> scope)- Specified by:
postProcessNonTranslatingin interfaceTranslationContext- Parameters:
postProcessor- id post processor for TRANSLATED purposescope- code to which the post processor applies
-
isPostProcessingNonTranslating
public boolean isPostProcessingNonTranslating()
- Specified by:
isPostProcessingNonTranslatingin interfaceTranslationContext- Returns:
- true if non-translating post processor is set
-
getMergeContext
public MergeContext getMergeContext()
- Specified by:
getMergeContextin interfaceTranslationContext
-
addExplicitId
public void addExplicitId(@NotNull @NotNull Node node, @Nullable @Nullable java.lang.String id, @NotNull @NotNull NodeFormatterContext context, @NotNull @NotNull MarkdownWriter markdown)Description copied from interface:ExplicitAttributeIdProviderUsed by AttributesExtension to insert attributes for headings during merge- Specified by:
addExplicitIdin interfaceExplicitAttributeIdProvider- Parameters:
node- nodeid- explicit idcontext- contextmarkdown- markdown writer
-
getIdGenerator
public HtmlIdGenerator getIdGenerator()
- Specified by:
getIdGeneratorin interfaceTranslationContext
-
-