Link transformer for data- attribute
We have an already-built component that utilizes a third party JavaScript API. There is a textfield property entered by a content author that is ultimately read by the JavaScript API to display a message. The property is stored in a data-* attribute in the HTML.
We want to change the textfield to a richtext so rich text features can be enabled, like bold, italic, and creating a link. The data-* attribute supports containing html. The problem is an <a href> tag/attribute in the HTML that is contained within the data-* attribute does not get transformed via Link Checker Transformer because it is quoted HTML in an attribute rather than real HTML.
HTML Example:
<option value="message" data-alert="<p>Message here with a <a href="/content/project/site/en/about.html">link</a> to an internal page.</p>" hidden="true">alert</option>
I am not sure how to tell the link transformer to process that HTML as HTML, finding the <a href> tag/attribute and translating the link per etc/map configuration.
Possible solutions
- In JavaScript I could write code to search and replace portions of the link using the same rules that are in etc/map, but that seems redundant. IE search for "/content/project/site/en/" and replace with "/" making a relative link of /about.html.
- A model could be written to do the same thing, but again redundant.
- Ideally, there is away to send that AEM property through the link transformer immediately as it is written into the HTML. I am not sure how to do that.
- Maybe there is a better solution?
AEM 6.5.17