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 Nov 17, 2022
1 parent 53aa9a2 commit ac81765
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 ac81765

Please sign in to comment.