fix(document): preserve rel attribute on links during parse and serialize#449
Open
surohak wants to merge 3 commits into
Open
fix(document): preserve rel attribute on links during parse and serialize#449surohak wants to merge 3 commits into
surohak wants to merge 3 commits into
Conversation
…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`)
Contributor
|
Someone is attempting to deploy a commit to the Nuxt Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Studio unconditionally strips the
relattribute 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
relattribute:{rel="nofollow"}is stripped from the outputRoot Cause
Two
visit()calls iterate all<a>elements andReflect.deleteProperty(node.props, 'rel'):generateDocumentFromMarkdownContent(parse path)generateContentFromMarkdownDocument(serialize path)The
preserveLinkAttributesoption was added as a partial workaround for comparison logic, but the stripping still happened during normal editing flows.Fix
Remove both
rel-strippingvisit()calls entirely. User-authoredrelattributes should always be preserved through round-trips. ThepreserveLinkAttributesoption is no longer needed and is removed.Changes
src/module/src/runtime/utils/document/generate.ts: Remove bothvisit()calls that striprel, clean up unused importssrc/module/src/runtime/utils/document/compare.ts: RemovepreserveLinkAttributes: trueoption (no longer needed)src/app/src/types/content.ts: RemovepreserveLinkAttributesfromMarkdownParsingOptionsImpact
After this change, any
relattributes in MDC link syntax will survive Studio editing:{rel="nofollow"}— for SEO control{rel="noopener"}— for security{rel="sponsored"}— for affiliate links