mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-16 18:46:57 +02:00
fix(v2): parse headings directly after h1 properly (#4641)
This commit is contained in:
parent
c8cf48a355
commit
808b0fa62a
2 changed files with 17 additions and 1 deletions
|
@ -152,6 +152,22 @@ describe('parseMarkdownContentTitle', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Should parse markdown h1 title at the top and next one after it', () => {
|
||||||
|
const markdown = dedent`
|
||||||
|
|
||||||
|
# Markdown Title
|
||||||
|
|
||||||
|
## Heading 2
|
||||||
|
|
||||||
|
Lorem Ipsum
|
||||||
|
|
||||||
|
`;
|
||||||
|
expect(parseMarkdownContentTitle(markdown)).toEqual({
|
||||||
|
content: '## Heading 2\n\nLorem Ipsum',
|
||||||
|
contentTitle: 'Markdown Title',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('Should parse markdown h1 alternate title', () => {
|
test('Should parse markdown h1 alternate title', () => {
|
||||||
const markdown = dedent`
|
const markdown = dedent`
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,7 @@ export function parseMarkdownContentTitle(
|
||||||
|
|
||||||
const content = contentUntrimmed.trim();
|
const content = contentUntrimmed.trim();
|
||||||
|
|
||||||
const regularTitleMatch = /^(?<pattern>#\s*(?<title>[^#\n]*)+\s*#*[\s\r]*?\n*?)/g.exec(
|
const regularTitleMatch = /^(?<pattern>#\s*(?<title>[^#\n]*)+[ \t]*#?\n*?)/g.exec(
|
||||||
content,
|
content,
|
||||||
);
|
);
|
||||||
const alternateTitleMatch = /^(?<pattern>\s*(?<title>[^\n]*)\s*\n[=]+)/g.exec(
|
const alternateTitleMatch = /^(?<pattern>\s*(?<title>[^\n]*)\s*\n[=]+)/g.exec(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue