vimtor / eleventy-plugin-external-links

Eleventy plugin to make all external links open securely in a new tab
https://www.npmjs.com/package/eleventy-plugin-external-links
MIT License
9 stars 1 forks source link

the plugin overwrites already existing `rel` and `target` attributes #7

Open cknoll opened 2 years ago

cknoll commented 2 years ago

In some cases we have some template code like

<a rel="me noopener" href="https://mastodon.social/@myprofile">my mastodon profile</p>

where the me string is used for link verification, see https://docs.joinmastodon.org/user/profile/#verification.

Currently, the plugin overwrites the attribute with rel="noopener" regardless of its previous content.

IMHO the plugin should leave a-tags which already have a specified relattribute untouched, because we can assume that the template author knew what they were doing.

Same should hold for target attributes.

cknoll commented 2 years ago

My current workaround : edit the config file .eleventy.js and replace the default regex with /^(([a-z]+:)|(\/\/))/iwith one that uses a negative look ahead (using the the syntax (?!XYZ)).

In particular for domain names that start with "mastodon": /^(([a-z]+:)(?!\/\/mastodon)|(\/\/))/i.

Helpfull online tool for this: https://regex101.com/