pre-processors for artificial role mapping
Optional
tostrategy to extract the role attribute value
from the element; any truthy value returned will be applied as xlink:role
attribute.
Optional
tothe 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:role
according to given pre-processors.What are artificial
xlink:role
attributes?Despite for
xlink:show="other"
the attributexlink:role
is expected to be unset, when it comes to representing the attributes astarget
attribute in view layers of CKEditor 5.Thus, if
xlink:show
is different to"other"
, butxlink:role
is set, this attribute is denoted as being artificial.What happens to an artificial
xlink:role
attribute by default?By default, such an attribute is encoded into the
target
attribute in a bijective manner, which is, that from the giventarget
attribute value in view layers, the correspondingxlink:show
andxlink:role
values can still be determined.When to use
mapArtificialXLinkRole
?As the CoreMedia Rich Text 1.0 DTD does not define an artificial
xlink:role
as invalid, it is perfectly fine, ifxlink:role
is used to hold data unrelated to thetarget
behavior.Creating a rule configuration by this factory method and applying it to your custom rules configuration provides the opportunity to store such
xlink:role
in a different attribute.How to deal with
toData
processing?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:role
even forxlink:show
states different toother
, for example, if settingtarget
in view layers to_embed_someRole
. In these cases, the default processing will override anyxlink:role
created 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 intoView
mapping and of course does not apply anyxlink:role
in itstoData
mapping.Example: Store in
class
attribute: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.