From 26abebeb4a78f0c1326be69882d9f4cb211560d7 Mon Sep 17 00:00:00 2001 From: Harini Date: Mon, 17 Aug 2026 12:12:44 +0530 Subject: [PATCH] fix(content-docs): detect h1 title when export declaration precedes it When an MDX file has an export declaration (e.g. `export function Foo`) before the h1 heading, parseMarkdownContentTitle failed to detect the title. The regex that strips preamble declarations before searching for the h1 only handled `import` statements, not `export` ones. Changing the regex alternation from `import\s` to `(?:import|export)\s` causes export blocks followed by a blank line to be skipped the same way import blocks are, so the title search correctly reaches the h1. Fixes #12331 --- packages/docusaurus-utils/src/markdownUtils.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/docusaurus-utils/src/markdownUtils.ts b/packages/docusaurus-utils/src/markdownUtils.ts index 216d0122e7ad..0b5530c1eeeb 100644 --- a/packages/docusaurus-utils/src/markdownUtils.ts +++ b/packages/docusaurus-utils/src/markdownUtils.ts @@ -255,11 +255,12 @@ export function parseMarkdownContentTitle( const removeContentTitleOption = options?.removeContentTitle ?? false; const content = contentUntrimmed.trim(); - // We only need to detect import statements that will be parsed by MDX as - // `import` nodes, as broken syntax can't render anyways. That means any block - // that has `import` at the very beginning and surrounded by empty lines. + // We only need to detect import/export statements that will be parsed by MDX + // as `import` or `export` nodes, as broken syntax can't render anyways. + // That means any block that has `import` or `export` at the very beginning + // and surrounded by empty lines. const contentWithoutImport = content - .replace(/^(?:import\s(?:.|\r?\n(?!\r?\n))*(?:\r?\n){2,})*/, '') + .replace(/^(?:(?:import|export)\s(?:.|\r?\n(?!\r?\n))*(?:\r?\n){2,})*/, '') .trim(); const regularTitleMatch = /^#[ \t]+(?[^ \t].*)(?:\r?\n|$)/.exec(