Skip to content

Commit

Permalink
fix(utils): allow partially backticked markdown h1 contentTitles (#8314)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaKGoldberg authored and slorber committed Jan 26, 2023
1 parent 0294171 commit 8ef6e62
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
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

0 comments on commit 8ef6e62

Please sign in to comment.