Skip to content

Incorrect page metadata when using markdown inline-code with XML tags inside #11818

Closed

Description

@SethFalco

Have you read the Contributing Guidelines on issues?

Prerequisites

Description

Docusaurus doesn't correctly generate the metadata fields on pages when the first sentence of a page includes inline-code syntax with something that looks like an XML taga inside.

Example:

Removes the <metadata> element from the document.

Removes the [`<metadata>`](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/metadata) element from the document.

Reproducible demo

https://github.com/SethFalco/metadata-sandbox

Steps to reproduce

  1. Clone the repo
  2. yarn install
  3. yarn run build
  4. Inspect build/docs/index.html

Expected behavior

They should be:

<meta data-rh="true" name="description" content="Removes the &lt;metadata&gt; element from the document.">

<meta data-rh="true" property="og:description" content="Removes the &lt;metadata&gt; element from the document.">

<p>Removes the <a href="https://developer.mozilla.org/en-US/docs/Web/SVG/Element/metadata" target="_blank" rel="noopener noreferrer" class=""><code>&lt;metadata&gt;</code></a> element from the document.</p>

Actual behavior

While the page itself renders correctly, the <metadata> nodes don't match what one would expect:

<meta data-rh="true" name="description" content="Removes the `` element from the document.">

<meta data-rh="true" property="og:description" content="Removes the `` element from the document.">

<p>Removes the <a href="https://developer.mozilla.org/en-US/docs/Web/SVG/Element/metadata" target="_blank" rel="noopener noreferrer" class=""><code>&lt;metadata&gt;</code></a> element from the document.</p>

Your environment

Self-service

  • I'd be willing to fix this bug myself.

Proposed Test Cases

packages/docusaurus-utils/src/__tests__/markdownUtils.test.ts

  it('creates excerpt with XML tag inside inline code', () => {
    expect(
      createExcerpt(dedent`
          # Markdown Regular Title

          This paragraph includes a link to the \`<metadata>\` documentation.
        `),
    ).toBe('This paragraph includes a link to the &lt;metadata&gt; documentation.');
  });

  it('creates excerpt with XML tag inside inline code with hyperlink', () => {
    expect(
      createExcerpt(dedent`
          # Markdown Regular Title

          This paragraph includes a link to the [\`<metadata>\`](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/metadata) documentation.
        `),
    ).toBe('This paragraph includes a link to the &lt;metadata&gt; documentation.');
  });

Results (truncated):

 FAIL  packages/docusaurus-utils/src/__tests__/markdownUtils.test.ts
  ● createExcerpt › creates excerpt with XML tag inside inline code

    Expected: "This paragraph includes a link to the &lt;metadata&gt; documentation."
    Received: "This paragraph includes a link to the `` documentation."

  ● createExcerpt › creates excerpt with XML tag inside inline code with hyperlink

    Expected: "This paragraph includes a link to the &lt;metadata&gt; documentation."
    Received: "This paragraph includes a link to the `` documentation."

Activity

  1. added
    bug
    status: needs triage
    on Mar 19, 2026
  2. changed the title [-]Incorrect page metadata when using markdown inline-code links[/-] [+]Incorrect page metadata when using markdown inline-code with XML tags[/+] on Mar 19, 2026
  3. changed the title [-]Incorrect page metadata when using markdown inline-code with XML tags[/-] [+]Incorrect page metadata when using markdown inline-code with XML tags inside[/+] on Mar 19, 2026
  4. added a commit that references this issue on Apr 1, 2026
    fcc5de7
  5. venkat22022202 commented on Apr 1, 2026

    @venkat22022202

    I've opened a fix for this in #11871.

    Root cause: In createExcerpt() (packages/docusaurus-utils/src/markdownUtils.ts), the HTML tag removal regex (.replace(/<[^>]*>/g, '')) runs before the inline code regex (.replace(/(.+?)/g, '$1')). This means <metadata> inside backticks is stripped as an HTML tag first, leaving behind empty backticks and broken output.

    Fix: Move the inline code replacement before the HTML tag removal, and escape angle brackets in the extracted code content to &lt;/&gt; so they aren't consumed by the HTML stripping step.

    All existing tests pass, and I've added the two test cases from this issue.

  6. removed
    status: needs triage
    on Apr 2, 2026
  7. perashanid commented on Apr 2, 2026

    @perashanid

    Hi! I'd like to work on this issue. The test cases you provided are very helpful. I'll investigate the createExcerpt function in markdownUtils and submit a fix. Thanks!

  8. added 2 commits that reference this issue on Apr 2, 2026
    4bcfce1
    7c60825
  9. slorber commented on Apr 2, 2026

    @slorber
    Collaborator

    There's already another pending PR with review comments: #11821

    Let's first ask for @SethFalco his plan to complete it. You can submit a new PR if no response within 1 week. Please do not use AI for your first PRs here, you must fully understand the changes you make.

  10. SethFalco commented on Apr 2, 2026

    @SethFalco
    ContributorAuthor

    I do have plans to complete it and apologize for stalling on this one!

    I opened it right before moving home, and am now busy with the cleaning/moving in to my new place. 😅

    If @perashanid would like to give it a shot, they are more than welcome to. (I'd recommend looking at #11821 to know where to work and to understand the gotcha I tripped on.)

    If this is still not resolved in 2 weeks, I should be good to finish up if no one else is iterating on it! 👍

    The test cases you provided are very helpful.

    I think the test cases I proposed may be flawed, FYI! My PR passes the tests, but is susceptible to other problems. See the review comments!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions