#12507·docusaurus

Markdown image alt text is HTML-escaped twice (`'` renders as `'`)

Author: w0244079Created Sep 25, 2026Updated Sep 25, 2026

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

The alt text of a local Markdown image is HTML-escaped twice, so apostrophes, quotes and ampersands reach the rendered page as literal entity text. Screen readers then read them out, for example "organization ampersand hash 39 s".

![An organization's repository list](/img/example.png) renders as:

xml
<img alt="An organization&amp;#39;s repository list" ...>

so the DOM alt value is An organization&#39;s repository list.

The cause is packages/docusaurus-mdx-loader/src/remark/transformImage/index.ts, which still runs escapeHtml() on alt and title before storing them as mdxJsxAttribute values:

typescript
if (node.alt) {
  attributes.push({
    type: 'mdxJsxAttribute',
    name: 'alt',
    value: escapeHtml(node.alt),
  });
}

That escape was needed in v2, when this plugin emitted a JSX string (see #3751: the build failed on " in alt text). Since the MDX v2 upgrade (#8288) it builds a JSX AST node instead, and attribute values are escaped again when rendered. The first escape is now redundant, so the text is escaped twice. The compiled page module contains alt:"An organization&#39;s repository list".

transformLinks does the same with the title of links to local assets (escapeHtml(node.title)).

A possible fix is to drop the escapeHtml() calls for alt and title in transformImage, and for title in transformLinks, and to add a test with ', " and & in alt text.

Reproducible demo

No response

Steps to reproduce

  1. Create a site: npx create-docusaurus@latest my-site classic.
  2. In docs/intro.md, add: ![The team's "logo" & mascot](/img/logo.svg)
  3. Run npm run build (or npm start) and inspect the image.

Expected behavior

The image's alt attribute is The team's "logo" & mascot.

Actual behavior

The alt attribute is The team&#39;s &quot;logo&quot; &amp; mascot. The built HTML contains alt="The team&amp;#39;s &amp;quot;logo&amp;quot; &amp;amp; mascot".

Your environment

  • Docusaurus version used: 3.10.2 (@docusaurus/mdx-loader 3.10.2), with @docusaurus/faster
  • Environment name and version: Node.js 26.8.2
  • Operating system and version: Linux (GitHub Codespaces)

Self-service

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