diff --git a/packages/markdown/parseMarkdown.js b/packages/markdown/parseMarkdown.js index 82c288021dee25..72a29b6965ca17 100644 --- a/packages/markdown/parseMarkdown.js +++ b/packages/markdown/parseMarkdown.js @@ -152,7 +152,7 @@ function getHeaders(markdown) { return headers; } catch (err) { throw new Error( - `docs-infra: ${err.message} in getHeader(markdown) with markdown: \n\n${header}`, + `docs-infra: ${err.message} in getHeader(markdown) with markdown: \n\n${header}\n`, ); } } @@ -274,7 +274,7 @@ function createRender(context) { }); } else if (level === 3) { if (!toc[toc.length - 1]) { - throw new Error(`docs-infra: Missing parent level for: ${headingText}`); + throw new Error(`docs-infra: Missing parent level for: ${headingText}\n`); } toc[toc.length - 1].children.push({ @@ -454,7 +454,7 @@ function prepareMarkdown(config) { const description = headers.description || getDescription(markdown); if (title == null || title === '') { - throw new Error(`docs-infra: Missing title in the page: ${location}`); + throw new Error(`docs-infra: Missing title in the page: ${location}\n`); } if (title.length > 70) { @@ -463,12 +463,13 @@ function prepareMarkdown(config) { `docs-infra: The title "${title}" is too long (${title.length} characters).`, 'It needs to have fewer than 70 characters—ideally less than 60. For more details, see:', 'https://developers.google.com/search/docs/advanced/appearance/title-link', + '', ].join('\n'), ); } if (description == null || description === '') { - throw new Error(`docs-infra: Missing description in the page: ${location}`); + throw new Error(`docs-infra: Missing description in the page: ${location}\n`); } if (description.length > 170) { @@ -477,6 +478,7 @@ function prepareMarkdown(config) { `docs-infra: The description "${description}" is too long (${description.length} characters).`, 'It needs to have fewer than 170 characters—ideally less than 160. For more details, see:', 'https://ahrefs.com/blog/meta-description/#4-be-concise', + '', ].join('\n'), ); } diff --git a/packages/markdown/parseMarkdown.test.js b/packages/markdown/parseMarkdown.test.js index 25bb7ee8a95809..ce6f6391d16dc2 100644 --- a/packages/markdown/parseMarkdown.test.js +++ b/packages/markdown/parseMarkdown.test.js @@ -452,9 +452,7 @@ authors: }).to.throw(`docs-infra: Missing trailing slash. The following link: [foo](/foo) in /test/bar/index.md is missing a trailing slash, please add it. -See https://ahrefs.com/blog/trailing-slash/ for more details. - -Please report this to https://github.com/markedjs/marked.`); +See https://ahrefs.com/blog/trailing-slash/ for more details.`); }); it('should report missing leading splashes', () => { @@ -473,9 +471,7 @@ Please report this to https://github.com/markedjs/marked.`); translations: [{ filename: 'index.md', markdown, userLanguage: 'en' }], }); }).to.throw(`docs-infra: Missing leading slash. The following link: -[foo](foo/) in /test/bar/index.md is missing a leading slash, please add it. - -Please report this to https://github.com/markedjs/marked.`); +[foo](foo/) in /test/bar/index.md is missing a leading slash, please add it.`); }); it('should report title too long', () => { @@ -516,4 +512,30 @@ It needs to have fewer than 170 characters—ideally less than 160. For more det https://ahrefs.com/blog/meta-description/#4-be-concise`); }); }); + + it('should not accept sh', () => { + const markdown = ` +# Foo + +

Fo

+ +\`\`\`sh +npm install @mui/material +\`\`\` + +`; + + expect(() => { + prepareMarkdown({ + ...defaultParams, + translations: [{ filename: 'index.md', markdown, userLanguage: 'en' }], + }); + }).to.throw(`docs-infra: Unsupported language: "sh" in: + +\`\`\`sh +npm install @mui/material +\`\`\` + +Use "bash" instead.`); + }); }); diff --git a/packages/markdown/prism.js b/packages/markdown/prism.js index 3a27f0c086e412..4fff68849135a1 100644 --- a/packages/markdown/prism.js +++ b/packages/markdown/prism.js @@ -20,7 +20,18 @@ function highlight(code, language) { break; case 'sh': - throw new Error([`Unsupported language: "sh", "${code}".`, 'Use "bash" instead.'].join('\n')); + throw new Error( + [ + `docs-infra: Unsupported language: "sh" in:`, + '', + '```sh', + code, + '```', + '', + 'Use "bash" instead.', + '', + ].join('\n'), + ); case 'diff': prismLanguage = { ...prism.languages.diff };