Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/pages/package/[[org]]/[name].vue
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,6 @@ const showSkeleton = shallowRef(false)
:latest-version="latestVersion"
:provenance-data="provenanceData"
:provenance-status="provenanceStatus"
:class="$style.areaHeader"
page="main"
:version-url-pattern="versionUrlPattern"
/>
Expand Down
16 changes: 15 additions & 1 deletion server/utils/readme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,11 +549,23 @@
toc.push({ text: plainText, id, depth })
}

// The browser doesn't support anchors within anchors and automatically extracts them from each other,
// causing a hydration error. To prevent this from happening in such cases, we use the anchor separately
if (htmlAnchorRe.test(displayHtml)) {
return `<h${semanticLevel} id="${id}" data-level="${depth}"${preservedAttrs}>${displayHtml}<a href="#${id}"></a></h${semanticLevel}>\n`
Comment thread
alexdln marked this conversation as resolved.
Comment thread
serhalp marked this conversation as resolved.
}

return `<h${semanticLevel} id="${id}" data-level="${depth}"${preservedAttrs}><a href="#${id}">${displayHtml}</a></h${semanticLevel}>\n`
}

renderer.heading = function ({ tokens, depth }: Tokens.Heading) {
const displayHtml = this.parser.parseInline(tokens)
const anchorTokenRegex = /^<a(\s.+)?\/?>$/

Check warning on line 562 in server/utils/readme.ts

View workflow job for this annotation

GitHub Actions / 🤖 Autofix code

regexp(no-unused-capturing-group)

Capturing group number 1 is defined but never used.

Check warning on line 562 in server/utils/readme.ts

View workflow job for this annotation

GitHub Actions / 🔠 Lint project

regexp(no-unused-capturing-group)

Capturing group number 1 is defined but never used.
Comment thread
serhalp marked this conversation as resolved.
Outdated
const isAnchorHeading =
anchorTokenRegex.test(tokens[0]?.raw ?? '') && tokens[tokens.length - 1]?.raw === '</a>'

// for anchor headings, we will ignore user-added id and add our own
const tokensWithoutAnchor = isAnchorHeading ? tokens.slice(1, -1) : tokens
const displayHtml = this.parser.parseInline(tokensWithoutAnchor)
const plainText = getHeadingPlainText(displayHtml)
const slugSource = getHeadingSlugSource(displayHtml)
return processHeading(depth, displayHtml, plainText, slugSource)
Expand Down Expand Up @@ -643,6 +655,8 @@

const { resolvedHref, extraAttrs } = processLink(href, plainText || title || '')

if (!resolvedHref) return text

return `<a href="${resolvedHref}"${titleAttr}${extraAttrs}>${text}</a>`
}

Expand Down
Loading