@@ -48,16 +48,24 @@ function getFile(metadata) {
4848function mdToHtmlify ( oldContent , mdToHtml , metadata ) {
4949 let content = oldContent ;
5050 const mdLinks = [ ] ;
51+ const mdReferences = [ ] ;
5152
5253 // find any links to markdown files
53- const regex = / (?: \] \( ) (?: \. \/ ) ? ( [ ^ ' " ) \] \s > ] + \. m d ) / g;
54- let match = regex . exec ( content ) ;
55- while ( match !== null ) {
56- mdLinks . push ( match [ 1 ] ) ;
57- match = regex . exec ( content ) ;
54+ const linkRegex = / (?: \] \( ) (?: \. \/ ) ? ( [ ^ ' " ) \] \s > ] + \. m d ) / g;
55+ let linkMatch = linkRegex . exec ( content ) ;
56+ while ( linkMatch !== null ) {
57+ mdLinks . push ( linkMatch [ 1 ] ) ;
58+ linkMatch = linkRegex . exec ( content ) ;
59+ }
60+ // find any reference links to markdown files
61+ const refRegex = / (?: \] \: ) (?: \s ) ? (?: \. \/ | \. \. \/ ) ? ( [ ^ ' " ) \] \s > ] + \. m d ) / g;
62+ let refMatch = refRegex . exec ( content ) ;
63+ while ( refMatch !== null ) {
64+ mdReferences . push ( refMatch [ 1 ] ) ;
65+ refMatch = refRegex . exec ( content ) ;
5866 }
5967
60- // replace to their website html links
68+ // replace markdown links to their website html links
6169 new Set ( mdLinks ) . forEach ( mdLink => {
6270 let htmlLink = mdToHtml [ mdLink ] ;
6371 if ( htmlLink ) {
@@ -75,6 +83,25 @@ function mdToHtmlify(oldContent, mdToHtml, metadata) {
7583 ) ;
7684 }
7785 } ) ;
86+
87+ // replace markdown refernces to their website html links
88+ new Set ( mdReferences ) . forEach ( refLink => {
89+ let htmlLink = mdToHtml [ refLink ] ;
90+ if ( htmlLink ) {
91+ htmlLink = getPath ( htmlLink , siteConfig . cleanUrl ) ;
92+ htmlLink = htmlLink . replace ( '/en/' , `/${ metadata . language } /` ) ;
93+ htmlLink = htmlLink . replace (
94+ '/VERSION/' ,
95+ metadata . version && metadata . version !== env . versioning . latestVersion
96+ ? `/${ metadata . version } /`
97+ : '/' ,
98+ ) ;
99+ content = content . replace (
100+ new RegExp ( `\\]\\:(?:\\s)?(\\.\\/|\\.\\.\\/)?${ refLink } ` , 'g' ) ,
101+ `]: ${ htmlLink } ` ,
102+ ) ;
103+ }
104+ } ) ;
78105 return content ;
79106}
80107
0 commit comments