fix(v2): parse headings directly after h1 properly (#4641)

This commit is contained in:
Alexey Pyltsyn 2021-04-19 11:10:24 +03:00 committed by GitHub
parent c8cf48a355
commit 808b0fa62a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View file

@ -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', () => {
const markdown = dedent`

View file

@ -86,7 +86,7 @@ export function parseMarkdownContentTitle(
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,
);
const alternateTitleMatch = /^(?<pattern>\s*(?<title>[^\n]*)\s*\n[=]+)/g.exec(