diff --git a/packages/docusaurus-utils/src/__tests__/markdownUtils.test.ts b/packages/docusaurus-utils/src/__tests__/markdownUtils.test.ts index 34648991ba35..34a39e407f3b 100644 --- a/packages/docusaurus-utils/src/__tests__/markdownUtils.test.ts +++ b/packages/docusaurus-utils/src/__tests__/markdownUtils.test.ts @@ -194,6 +194,34 @@ describe('createExcerpt', () => { ); }); + it('creates excerpt for content containing colons without stripping intermediate text', () => { + expect( + createExcerpt(dedent` + Meeting runs 10:30:45 to 11:45:00 daily. + `), + ).toBe('Meeting runs 10:30:45 to 11:45:00 daily.'); + + expect( + createExcerpt(dedent` + Note: install first. Tip: run the build. + `), + ).toBe('Note: install first. Tip: run the build.'); + + expect( + createExcerpt(dedent` + We have introduced three types of item types in the example in the previous section: \`doc\`, \`category\`, and \`link\`, whose usages are fairly intuitive. We will formally introduce their APIs. There's also a fourth type: \`autogenerated\`, which we will explain in detail later. + `), + ).toBe( + "We have introduced three types of item types in the example in the previous section: doc, category, and link, whose usages are fairly intuitive. We will formally introduce their APIs. There's also a fourth type: autogenerated, which we will explain in detail later.", + ); + + expect( + createExcerpt(dedent` + Party :tada::sparkles: celebration! + `), + ).toBe('Party celebration!'); + }); + it('creates excerpt for heading specified with anchor-id syntax', () => { expect( createExcerpt(dedent` diff --git a/packages/docusaurus-utils/src/markdownUtils.ts b/packages/docusaurus-utils/src/markdownUtils.ts index 3a82a52cbb6e..ce2517db0e48 100644 --- a/packages/docusaurus-utils/src/markdownUtils.ts +++ b/packages/docusaurus-utils/src/markdownUtils.ts @@ -218,7 +218,7 @@ export function createExcerpt(fileString: string): string | undefined { // Remove admonition definition. .replace(/:::.*/, '') // Remove Emoji names within colons include preceding whitespace. - .replace(/\s?:(?:::|[^:\n])+:/g, '') + .replace(/\s?(?