Figures out the optimal order of marks, in order to minimize the amount of
nesting/repeated elements in environments such as HTML. For instance, a naive
implementation might render something like:
<strong>This block contains </strong> <strong><ahref="https://some.url/">a link</a></strong> <strong> and some bolded text</strong>
...whereas an optimal order would be:
<strong> This block contains <ahref="https://some.url/">a link</a> and some bolded text </strong>
This is particularly necessary for cases like links, where you don't want multiple
individual links for different segments of the link text, even if parts of it are
bolded/italicized.
This function is meant to be used like: block.children.map(sortMarksByOccurences),
and is used internally in buildMarksTree().
The marks are sorted in the following order:
Marks that are shared amongst the most adjacent siblings
Non-default marks (links, custom metadata)
Decorators (bold, emphasis, code etc), in a predefined, preferred order
Parameters
span: PortableTextSpan | TypedObject
The current span to sort
index: number
The index of the current span within the block
blockChildren: (PortableTextSpan | TypedObject)[]
All children of the block being sorted
Returns string[]
Array of decorators and annotations, sorted by "most adjacent siblings"
Figures out the optimal order of marks, in order to minimize the amount of nesting/repeated elements in environments such as HTML. For instance, a naive implementation might render something like:
...whereas an optimal order would be:
This is particularly necessary for cases like links, where you don't want multiple individual links for different segments of the link text, even if parts of it are bolded/italicized.
This function is meant to be used like:
block.children.map(sortMarksByOccurences)
, and is used internally inbuildMarksTree()
.The marks are sorted in the following order: