Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions packages/docusaurus-utils/src/__tests__/markdownUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,53 @@ Lorem Ipsum
});
});

it('parses markdown h1 title preserving trailing hash without preceding whitespace', () => {
expect(
parseMarkdownContentTitle(dedent`
# Learn C#

Lorem Ipsum
`),
).toEqual({
content: dedent`
# Learn C#

Lorem Ipsum
`,
contentTitle: 'Learn C#',
});

expect(
parseMarkdownContentTitle(dedent`
# F# {#fsharp-intro}

Lorem Ipsum
`),
).toEqual({
content: dedent`
# F# {#fsharp-intro}

Lorem Ipsum
`,
contentTitle: 'F#',
});

expect(
parseMarkdownContentTitle(dedent`
# Learn C# #

Lorem Ipsum
`),
).toEqual({
content: dedent`
# Learn C# #

Lorem Ipsum
`,
contentTitle: 'Learn C#',
});
});

it('parses markdown h1 title at the top followed by h2 title', () => {
const markdown = dedent`

Expand Down
3 changes: 2 additions & 1 deletion packages/docusaurus-utils/src/markdownUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ export function parseMarkdownContentTitle(
contentTitle: toTextContentTitle(
regularTitleMatch
.groups!.title!.trim()
.replace(/\s*(?:\{#*[\w-]+\}|#+)$/, ''),
.replace(/\s*\{#*[\w-]+\}$/, '')
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
.replace(/(?:\s+|^)#+$/, ''),
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
).trim(),
};
}
Expand Down