@@ -5,6 +5,7 @@ import { u as createTree } from 'unist-builder';
55import { SKIP , visit } from 'unist-util-visit' ;
66
77import buildExtraContent from './buildExtraContent.mjs' ;
8+ import { createLegacySlugger } from './slugger.mjs' ;
89import getConfig from '../../../utils/configuration/index.mjs' ;
910import {
1011 GITHUB_BLOB_URL ,
@@ -20,12 +21,14 @@ import { QUERIES, UNIST } from '../../../utils/queries/index.mjs';
2021 * @param {import('unist').Parent } parent The parent node of the current node
2122 * @returns {import('hast').Element } The HTML AST tree of the heading content
2223 */
23- const buildHeading = ( { data, children, depth } , index , parent ) => {
24+ const buildHeading = ( { data, children, depth } , index , parent , legacySlug ) => {
2425 // Creates the heading element with the heading text and the link to the heading
2526 const headingElement = createElement ( `h${ depth + 1 } ` , [
2627 // The inner Heading markdown content is still using Remark nodes, and they need
2728 // to be converted into Rehype nodes
2829 ...children ,
30+ // Legacy anchor alias to preserve old external links
31+ createElement ( 'span' , createElement ( `a#${ legacySlug } ` ) ) ,
2932 // Creates the element that references the link to the heading
3033 // (The `#` anchor on the right of each Heading section)
3134 createElement (
@@ -220,6 +223,8 @@ const buildMetadataElement = (node, remark) => {
220223 * @param {import('unified').Processor } remark The Remark instance to be used to process
221224 */
222225export default ( headNodes , metadataEntries , remark ) => {
226+ const legacySlugger = createLegacySlugger ( ) ;
227+
223228 // Creates the root node for the content
224229 const parsedNodes = createTree (
225230 'root' ,
@@ -229,7 +234,13 @@ export default (headNodes, metadataEntries, remark) => {
229234 const content = structuredClone ( entry . content ) ;
230235
231236 // Parses the Heading nodes into Heading elements
232- visit ( content , UNIST . isHeading , buildHeading ) ;
237+ visit ( content , UNIST . isHeading , ( node , index , parent ) => {
238+ const legacySlug = legacySlugger . getLegacySlug (
239+ node . data . text ,
240+ entry . api
241+ ) ;
242+ buildHeading ( node , index , parent , legacySlug ) ;
243+ } ) ;
233244
234245 // Parses the Blockquotes into Stability elements
235246 // This is treated differently as we want to preserve the position of a Stability Index
0 commit comments