In just released EarmarkParser 1.4.15 which allows disabling of inline rendering
If this is a desired feature for Earmark (which I doubt, but I am occasionally mistaken, where occasionally ~ 99.9%)
please let me know and I will add an option and upgrade the dependency.
IMO it is definitely a feature of the renderer. The AST should stay as close as possible to the source.
I think the default behavior of opening in a separate tab or not is very application dependent, so an option is best. Has anyone requested this feature so far?
If it helps any, in a number of custom sites I’ve put together I typically stick with this rule and it hasn’t failed yet:
If the hostname is my domain, don’t add these attributes
If the hostname is not my domain (ie. an external link)
If there’s no existing rel attr, add the noopener attr
If there’s an existing rel attr, use the existing rel attrs as is
Using noopener is the security related rel attr you’ll want to use in combination with target blank.
I know I edited and deleted my previous reply but it was correct. Using nofollow will tell search engines to ignore the link for page rankings. IMO that’s not something you would want to set by default, but using the above flow chart of conditions you can assign nofollow manually as needed (such as for user generated links in comments or another untrusted source).
I think it’s a reasonable idea to assign noopener / target new for all external links.
I’m not sure what the config API would look like but it would be neat if users had the flexibility to run custom code to determine how these attributes get applied.
For example, maybe there’s a baseline config option that says “yes, for all external links add noopener / target new”, but you could overwrite that as a user and the option accepts a function which has access to any necessary params to determine the hostname, if it’s on a subdomain, etc. basically anything needed to programmatically see if this should be set?
I’ll be completely honest with you, I don’t use Earmark but I have used this feature before with static site generators that support Markdown. It’s very convenient to be able to write out links without having to manually decorate them with rel attrs and target blank when you know it’s an external link that you want to open in a new window.
It also sets you up to be able to add little visual cues too like a tiny icon with an arrow that shows it’s an external link. Stuff like this is especially useful when you have a blog with hundreds of posts and thousands of links. Doing this thousands of times manually is tedious.