Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(utils): allow partially backticked markdown h1 contentTitles #8314

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 15 additions & 1 deletion packages/docusaurus-utils/src/__tests__/markdownUtils.test.ts
Expand Up @@ -195,7 +195,7 @@ describe('parseMarkdownContentTitle', () => {
});
});

it('parses markdown h1 title at the top and unwrap inline code block', () => {
it('parses markdown h1 title inside backticks at the top and unwrap inline code block', () => {
const markdown = dedent`

# \`Markdown Title\`
Expand All @@ -209,6 +209,20 @@ describe('parseMarkdownContentTitle', () => {
});
});

it('parses markdown h1 title with interspersed backticks at the top and unwrap inline code block', () => {
const markdown = dedent`

# Markdown \`Title\` With \`Many\` Backticks!

Lorem Ipsum

`;
expect(parseMarkdownContentTitle(markdown)).toEqual({
content: markdown,
contentTitle: 'Markdown Title With Many Backticks!',
});
});

it('parses markdown h1 title and trim content', () => {
const markdown = `

Expand Down
5 changes: 1 addition & 4 deletions packages/docusaurus-utils/src/markdownUtils.ts
Expand Up @@ -155,10 +155,7 @@ export function parseFrontMatter(markdownFileContent: string): {
}

function toTextContentTitle(contentTitle: string): string {
if (contentTitle.startsWith('`') && contentTitle.endsWith('`')) {
return contentTitle.substring(1, contentTitle.length - 1);
}
return contentTitle;
return contentTitle.replace(/`(?<text>[^`]*)`/g, '$<text>');
}

type ParseMarkdownContentTitleOptions = {
Expand Down