@@ -22,6 +22,13 @@ const walkFiles = (pathToWalk) => {
2222
2323const allFiles = walkFiles ( 'content' ) . concat ( walkFiles ( 'data' ) )
2424
25+ // The script will throw an error if it finds any markup not represented here.
26+ // Hacky but it captures the current rare edge cases.
27+ const linkInlineMarkup = {
28+ 'emphasis' : '*' ,
29+ 'strong' : '**'
30+ }
31+
2532// [start-readme]
2633//
2734// Run this script to find internal links in all content and data Markdown files, check if either the title or link
@@ -76,10 +83,22 @@ async function main () {
7683 // For every Markdown link...
7784 for ( const node of nodesPerFile ) {
7885 const oldLink = node . url
86+
87+ // Find and preserve any inline markup in link titles, like [*Foo*](/foo)
88+ let inlineMarkup = ''
89+ if ( node . children [ 0 ] . children ) {
90+ inlineMarkup = linkInlineMarkup [ node . children [ 0 ] . type ]
91+
92+ if ( ! inlineMarkup ) {
93+ console . error ( `Cannot find an inline markup entry for ${ node . children [ 0 ] . type } !` )
94+ process . exit ( 1 )
95+ }
96+ }
97+
7998 const oldTitle = node . children [ 0 ] . value || node . children [ 0 ] . children [ 0 ] . value
80- const oldMarkdownLink = `[${ oldTitle } ](${ oldLink } )`
99+ const oldMarkdownLink = `[${ inlineMarkup } ${ oldTitle } ${ inlineMarkup } ](${ oldLink } )`
81100
82- // As a blanket rule, only update links with quotes around them.
101+ // As a blanket rule, only update titles in links that have quotes around them.
83102 // Update: "[Foo](/foo)"
84103 // Do not update: [Bar](/bar)
85104 let noQuotesAroundLink
@@ -133,7 +152,7 @@ async function main () {
133152 // because Markdown links don't include versioning.
134153 newLink = versionMatch ? `/${ versionMatch [ 1 ] } ${ getPathWithoutVersion ( newLink ) } ` : getPathWithoutVersion ( newLink )
135154
136- let newMarkdownLink = `[${ newTitle } ](${ newLink } )`
155+ let newMarkdownLink = `[${ inlineMarkup } ${ newTitle } ${ inlineMarkup } ](${ newLink } )`
137156
138157 // Handle a few misplaced quotation marks.
139158 if ( oldMarkdownLink . includes ( '["' ) ) {
0 commit comments