mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-01 19:27:48 +02:00
fix(utils): allow partially backticked markdown h1 contentTitles (#8314)
This commit is contained in:
parent
029417154c
commit
8ef6e623ac
2 changed files with 16 additions and 5 deletions
|
@ -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`
|
const markdown = dedent`
|
||||||
|
|
||||||
# \`Markdown Title\`
|
# \`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', () => {
|
it('parses markdown h1 title and trim content', () => {
|
||||||
const markdown = `
|
const markdown = `
|
||||||
|
|
||||||
|
|
|
@ -155,10 +155,7 @@ export function parseFrontMatter(markdownFileContent: string): {
|
||||||
}
|
}
|
||||||
|
|
||||||
function toTextContentTitle(contentTitle: string): string {
|
function toTextContentTitle(contentTitle: string): string {
|
||||||
if (contentTitle.startsWith('`') && contentTitle.endsWith('`')) {
|
return contentTitle.replace(/`(?<text>[^`]*)`/g, '$<text>');
|
||||||
return contentTitle.substring(1, contentTitle.length - 1);
|
|
||||||
}
|
|
||||||
return contentTitle;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ParseMarkdownContentTitleOptions = {
|
type ParseMarkdownContentTitleOptions = {
|
||||||
|
|
Loading…
Add table
Reference in a new issue