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

This commit is contained in:
Josh Goldberg 2022-11-17 05:38:10 -05:00 committed by sebastienlorber
parent 029417154c
commit 8ef6e623ac
2 changed files with 16 additions and 5 deletions

View file

@ -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\`
@ -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 = `

View file

@ -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 = {