mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-11 08:07:26 +02:00
fix(utils): parse Markdown headings with CRLF line break (#7043)
This commit is contained in:
parent
5fb09a2946
commit
4f4f503633
2 changed files with 19 additions and 3 deletions
|
@ -253,6 +253,22 @@ Lorem Ipsum
|
|||
});
|
||||
});
|
||||
|
||||
it('parses markdown h1 title with CRLF break', () => {
|
||||
const markdown = `# Markdown Title\r\n\r\nLorem Ipsum`;
|
||||
expect(parseMarkdownContentTitle(markdown)).toEqual({
|
||||
content: markdown,
|
||||
contentTitle: 'Markdown Title',
|
||||
});
|
||||
});
|
||||
|
||||
it('parses markdown h1 setext title with CRLF break', () => {
|
||||
const markdown = `Markdown Title\r\n=====\r\n\r\nLorem Ipsum`;
|
||||
expect(parseMarkdownContentTitle(markdown)).toEqual({
|
||||
content: markdown,
|
||||
contentTitle: 'Markdown Title',
|
||||
});
|
||||
});
|
||||
|
||||
it('parses markdown h1 title at the top (atx style with closing #)', () => {
|
||||
const markdown = dedent`
|
||||
|
||||
|
|
|
@ -198,13 +198,13 @@ export function parseMarkdownContentTitle(
|
|||
// `import` nodes, as broken syntax can't render anyways. That means any block
|
||||
// that has `import` at the very beginning and surrounded by empty lines.
|
||||
const contentWithoutImport = content
|
||||
.replace(/^(?:import\s(?:.|\n(?!\n))*\n{2,})*/, '')
|
||||
.replace(/^(?:import\s(?:.|\r?\n(?!\r?\n))*(?:\r?\n){2,})*/, '')
|
||||
.trim();
|
||||
|
||||
const regularTitleMatch = /^#[ \t]+(?<title>[^ \t].*)(?:\n|$)/.exec(
|
||||
const regularTitleMatch = /^#[ \t]+(?<title>[^ \t].*)(?:\r?\n|$)/.exec(
|
||||
contentWithoutImport,
|
||||
);
|
||||
const alternateTitleMatch = /^(?<title>.*)\n=+(?:\n|$)/.exec(
|
||||
const alternateTitleMatch = /^(?<title>.*)\r?\n=+(?:\r?\n|$)/.exec(
|
||||
contentWithoutImport,
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue