Skip to content

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

@SethFalco

Description

@SethFalco

Have you read the Contributing Guidelines on issues?

Prerequisites

  • I'm using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • I have tried creating a repro with https://new.docusaurus.io.
  • I have read the console error message carefully (if applicable).

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

  • Public source code: https://github.com/svg/svgo.dev
  • Public site URL: https://svgo.dev
  • Docusaurus version used: v3.9.2
  • Environment name and version (e.g. Chrome 89, Node.js 16.4): Node.js v24.14.0
  • Operating system and version (e.g. Ubuntu 20.04.2 LTS): Debian Trixie

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."

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn error in the Docusaurus core causing instability or issues with its execution

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions