Skip to content

fix(document): preserve rel attribute on links during parse and serialize#449

Open
surohak wants to merge 3 commits into
nuxt-content:mainfrom
surohak:fix/preserve-link-rel-attribute
Open

fix(document): preserve rel attribute on links during parse and serialize#449
surohak wants to merge 3 commits into
nuxt-content:mainfrom
surohak:fix/preserve-link-rel-attribute

Conversation

@surohak
Copy link
Copy Markdown
Contributor

@surohak surohak commented May 6, 2026

Description

Studio unconditionally strips the rel attribute from all <a> elements both when parsing markdown into a document and when serializing back to markdown. This causes MDC attributes like {rel="nofollow"} to be lost through Studio editing round-trips.

Reproduction

  1. Create a markdown file with a link that has a rel attribute:
    [Example](https://example.com){rel="nofollow"}
  2. Open in Studio and make any edit
  3. Save/commit — the {rel="nofollow"} is stripped from the output

Root Cause

Two visit() calls iterate all <a> elements and Reflect.deleteProperty(node.props, 'rel'):

  • One in generateDocumentFromMarkdownContent (parse path)
  • One in generateContentFromMarkdownDocument (serialize path)

The preserveLinkAttributes option was added as a partial workaround for comparison logic, but the stripping still happened during normal editing flows.

Fix

Remove both rel-stripping visit() calls entirely. User-authored rel attributes should always be preserved through round-trips. The preserveLinkAttributes option is no longer needed and is removed.

Changes

  • src/module/src/runtime/utils/document/generate.ts: Remove both visit() calls that strip rel, clean up unused imports
  • src/module/src/runtime/utils/document/compare.ts: Remove preserveLinkAttributes: true option (no longer needed)
  • src/app/src/types/content.ts: Remove preserveLinkAttributes from MarkdownParsingOptions

Impact

After this change, any rel attributes in MDC link syntax will survive Studio editing:

  • {rel="nofollow"} — for SEO control
  • {rel="noopener"} — for security
  • {rel="sponsored"} — for affiliate links

…lize

Studio unconditionally strips the `rel` attribute from all `<a>` elements
both when parsing markdown into a document and when serializing back to
markdown. This causes MDC attributes like `{rel="nofollow"}` to be lost
through Studio editing round-trips.

The stripping was originally added to remove auto-injected `nofollow` from
the markdown parser, but it also removes intentional `rel` attributes set
by content authors (e.g. `nofollow`, `noopener`, `sponsored`).

Since the `preserveLinkAttributes` option was already added as a workaround
for comparison logic, and the proper fix is to always preserve user-set
attributes, this commit:

1. Removes the `rel` stripping in `generateDocumentFromMarkdownContent`
2. Removes the `rel` stripping in `generateContentFromMarkdownDocument`
3. Removes the now-unnecessary `preserveLinkAttributes` option from
   the type and call sites
4. Cleans up unused imports (`visit`, `MDCElement`, `Node`)
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 6, 2026

Someone is attempting to deploy a commit to the Nuxt Team on Vercel.

A member of the Team first needs to authorize it.

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