mirror of
https://github.com/xoofx/markdig.git
synced 2026-02-03 21:36:36 +00:00
rel='noopener' and rel='nofollow' as an additional option for links #383
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Atulin on GitHub (Jul 30, 2020).
Markdig already comes bundled with an extension –
.UseNoFollowLinks()– that ensures all links haverel='nofollow'attribute. .Meanwhile,
rel='noopener'ensures that the target won't be able to access the window object of the page linking to it, which could be a security issue, andrel='noreferrer'ensures that the target page doesn't know where the visit came from. It can break analytics if used for internal links, but can be desired for user-generated content.Proposed solution A:
Two more extensions, each adding its respective
relwith.UseNoOpenerLinks()and.UseNoReferrerLinks(). It's a bit verbose and might have some impact on performance, but it's fully backwards-compatible.Proposed solution B:
All three extensions merged into one,
.UseAdvancedLinks(), possibly with something akin to the following signature:which could be used with named parameters:
.UseAdvancedLinks(noreferrer: true, nofollow: true). This cuts down on the verbosity and could be a bit more performant since all three attributes could be set in a single pass, but the issue might be backwards compatibility – should.UseNoFollowLinks()be dropped – or redundancy – should it exist besides.UseNoFollowLinks().I tried implementing it myself (you can see my attempt here), but it turned out to be a task a bit too big for me. Perhaps some bigger brain will be able to implement it in a way that actually works.
@xoofx commented on GitHub (Jul 30, 2020):
Maybe an extension with
UseReferalLinks(params string[] names)that you can use directly withUseReferalLinks("nofollow")while we would keep onlyUseNoFollowLinks()using internally the useUseReferalLinks.I'm not in favor of the boolean approach, nor I think that an enum would be nice, as there are also several other possible values so keeping it simple should cover all future usecases.
Modifying the existing
NoFollowLinksextension should not be complicated to turn it into aReferalLinksExtension.