silverstripe/silverstripe-cms

Silverstripe image-shortcodes are picked up/shown as linkable in-page anchors

micschk opened this issue · 1 comments

Images are inserted as shortcode in the editor:
[image src="/assets/image.jpg" id="164" ... ]

The id="164" part is then picked up and shown as on-page linkable anchor in the selector of the anchor-link modal in the CMS. (When selected, an anchor link gets inserted as <a href="[sitetree_link,id=1]#164">...</a>).

Screenshot 2023-02-15 at 12 53 29

One option could be to fix the regex itself at SiteTree::getAnchorsOnPage() (NOTE: duplicated in Elemental).

But probably a better fix would be to process any shortcodes before filtering through the regex, as the result of shortcodes could theoretically contain linkable anchors as well?

But probably a better fix would be to process any shortcodes before filtering through the regex, as the result of shortcodes could theoretically contain linkable anchors as well?

Yes, that would definitely be the case in our projects where shortcodes can provide markup that may contain links and anchors, too. At the same time it might be tricky since the content may not be directly visible if one went to check it manually since the WYSIWYG would still just have the shortcode.