Skip to content

feat(theme): allow joining attr to external link#5123

Open
WizardsBowl wants to merge 1 commit intovuejs:mainfrom
WizardsBowl:fix-link-rel
Open

feat(theme): allow joining attr to external link#5123
WizardsBowl wants to merge 1 commit intovuejs:mainfrom
WizardsBowl:fix-link-rel

Conversation

@WizardsBowl
Copy link
Copy Markdown
Contributor

Description

I tried to add rel="nofollow" attribute to an external link and found it doesn't work.

My markdown file is like this:

[LINK](https://external.link){rel=nofollow} // use markdown-it-attrs plugin

And this is the final html:

<a href="https://external.link" rel="noreferrer" target="_blank">LINK</a>

It's rel attribute is an unexpected noreferrer but not nofollow.

That's because the linkPlugin always use attrSet and override the old value.

This PR add an option telling the linkPlugin to use attrSet or to use attrJoin for each attr.

linkPlugin(
  md,
  {
    target: '_blank',
    rel: { value: 'noreferrer', join: true },
    example1: 'will-override',
    example2: { value: 'will-override' },
    example3: { value: 'will-override', join: false },
    example4: { value: 'will-join-in', join: true },
    ...options.externalLinks
  },
  base,
  slugify
)

let externalLinks?: Record<string, string | ExternalLinkAttrValue>

export interface ExternalLinkAttrValue {
  value: string
  join?: boolean
}

The final html contains both nofollow and noreferrer:

<a href="https://external.link" rel="nofollow noreferrer" target="_blank">LINK</a>

Linked Issues

None.

Additional Context

The markdown-it-attrs plugin is built-in with VitePress.


Tip

The author of this PR can publish a preview release by commenting /publish below.

@brc-dd brc-dd force-pushed the main branch 3 times, most recently from 15a0278 to 09af6c7 Compare March 26, 2026 04:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant