pre-processors for artificial role mapping
OptionaltoData?: (element: HTMLAnchorElement) => string | undefinedstrategy to extract the role attribute value
from the element; any truthy value returned will be applied as xlink:role attribute.
OptionaltoView?: (element: HTMLAnchorElement, role: string) => voidthe toView mapping, which may store the
given value of xlink:role in some other attribute
excluded values of show when not to apply the
artificial role mapping; defaults to the recommended default ["other"]
Maps artificial
xlink:roleaccording to given pre-processors.What are artificial
xlink:roleattributes?Despite for
xlink:show="other"the attributexlink:roleis expected to be unset, when it comes to representing the attributes astargetattribute in view layers of CKEditor 5.Thus, if
xlink:showis different to"other", butxlink:roleis set, this attribute is denoted as being artificial.What happens to an artificial
xlink:roleattribute by default?By default, such an attribute is encoded into the
targetattribute in a bijective manner, which is, that from the giventargetattribute value in view layers, the correspondingxlink:showandxlink:rolevalues can still be determined.When to use
mapArtificialXLinkRole?As the CoreMedia Rich Text 1.0 DTD does not define an artificial
xlink:roleas invalid, it is perfectly fine, ifxlink:roleis used to hold data unrelated to thetargetbehavior.Creating a rule configuration by this factory method and applying it to your custom rules configuration provides the opportunity to store such
xlink:rolein a different attribute.How to deal with
toDataprocessing?If you stored the role in a different attribute, you should restore its value here and return it.
Caveat:
Editors may trigger the default mapping to handle
xlink:roleeven forxlink:showstates different toother, for example, if settingtargetin view layers to_embed_someRole. In these cases, the default processing will override anyxlink:rolecreated by the mapping generated here.This is assumed to be a very rare corner-case, though.
The all defaults scenario:
If you just invoke
mapArtificialXLinkRole()it will, by default, create a rule configuration that strips any artificial roles intoViewmapping and of course does not apply anyxlink:rolein itstoDatamapping.Example: Store in
classattribute:The following example demonstrates how to possibly store an artificial role within the class attribute of the anchor element:
Note for Custom Attributes:
For any other attribute you have chosen to store the role in, ensure, to register it as belonging to a link, so that, for example, removing the link will also clean up the role-representing attribute.