diff --git a/src/utilities/list2Tree/index.js b/src/utilities/list2Tree/index.js index 6934b4ce3a0d..ac00df0f35d4 100644 --- a/src/utilities/list2Tree/index.js +++ b/src/utilities/list2Tree/index.js @@ -24,11 +24,9 @@ function list2Tree(parent, anchors, topLevel = findTopLevel(anchors)) { children: list2Tree(hd.title, others, findTopLevel(others)), }; } else { - const match = /^.+(\s*\$#([a-z0-9\-_]+?)\$\s*)$/.exec(parent); - const newParent = match ? parent.replace(match[1], '').trim() : parent; return { ...c[0], - title2: c[0].title.replace(new RegExp(`^${newParent}\\.`, 'i'), ''), + title2: c[0].title.replace(new RegExp(`^${parent}\\.`, 'i'), ''), }; } }); diff --git a/src/utilities/process-readme.mjs b/src/utilities/process-readme.mjs index 13d04d92562b..bd05b4bc725e 100644 --- a/src/utilities/process-readme.mjs +++ b/src/utilities/process-readme.mjs @@ -76,7 +76,7 @@ function linkFixerFactory(sourceUrl) { console.log('REWRITE URL:', oldHref, '-->', href); } - return markdownLink.replace(oldHref, href); + return markdownLink.replaceAll(oldHref, href); }; } @@ -105,6 +105,7 @@ export default function processREADME(body, options = {}) { // EXAMPLE: [Contributing](./.github/CONTRIBUTING.md) // EXAMPLE: [Contributing](CONTRIBUTING.md) // EXAMPLE: [line-identifier]: https://webpack.js.org/loaders/ + // EXAMPLE: [`./src/config.d.ts`](./src/config.d.ts) .replace(inlineLinkRegex, linkFixerFactory(options.source)) // Replace any

with `##` .replace(/]*>/g, '## ') diff --git a/src/utilities/process-readme.test.mjs b/src/utilities/process-readme.test.mjs index 329aaac05880..a5f072cd26c4 100644 --- a/src/utilities/process-readme.test.mjs +++ b/src/utilities/process-readme.test.mjs @@ -28,4 +28,15 @@ describe('processReadme', () => { '- [html-webpack-plugin](https://github.com/jantimon/html-webpack-plugin)' ); }); + it('rewrite relative url', () => { + const options = { + source: + 'https://raw.githubusercontent.com/webpack-contrib/postcss-loader/master/README.md', + }; + const loaderMDData = + 'See the file [`./src/config.d.ts`](./src/config.d.ts).'; + expect(processReadme(loaderMDData, options)).toEqual( + 'See the file [`https://github.com/webpack-contrib/postcss-loader/blob/master/src/config.d.ts`](https://github.com/webpack-contrib/postcss-loader/blob/master/src/config.d.ts).' + ); + }); }); diff --git a/src/utilities/yaml-headmatter.mjs b/src/utilities/yaml-headmatter.mjs index dc5a400e2e21..beb5986cad47 100644 --- a/src/utilities/yaml-headmatter.mjs +++ b/src/utilities/yaml-headmatter.mjs @@ -2,7 +2,16 @@ export default function yamlHeadmatter(fields) { let ret = '---\n'; Object.keys(fields).map((field) => { - ret += `${field}: ${fields[field]}\n`; + if (field === 'contributors') { + if(fields[field].length) { + ret += `${field}:\n`; + fields[field].forEach((contributor) => { + ret += ` - ${contributor}\n`; + }); + } + } else { + ret += `${field}: ${fields[field]}\n`; + } }); ret = `${ret}---\n`;