Skip to content

fix(metadata): preserve MDX special symbols in inline code syntax - #11821

Merged
slorber merged 9 commits into
meta:mainfrom
SethFalco:metadata
Aug 24, 2026
Merged

slorber merged 9 commits into
meta:mainfrom
SethFalco:metadata

Conversation

@SethFalco

@SethFalco SethFalco commented Mar 19, 2026 •

Copy link
Copy Markdown
Contributor

Pre-flight checklist

  • I have read the Contributing Guidelines on pull requests.
  • If this is a code change: I have written unit tests and/or added dogfooding pages to fully verify the new behavior.
  • N/A If this is a new API or substantial change: the PR has an accompanying issue (closes #0000) and the maintainers have approved on my working plan.

Motivation

The metadata on my SVGO.dev is screwy. :c

This fixes the bug so that the metadata shows the correct description.

Test Plan

I've added two new test cases, a dogfooding page, and can demonstrate it fixes the issue on a live page on Docusaurus.io. The latter is easiest to visualize through Open Graph embeds.

Before After
Existing issue on production docusaurus.io image
Dogfooding Page No screenshot for the dogfooding page as it didn't exist yet.

I also have what is effectively this patch deployed to SVGO.dev, so it's being tested there:

Test links

Deploy preview: https://deploy-preview-11821--docusaurus-2.netlify.app/

Related issues/PRs

@meta-cla meta-cla Bot added the CLA Signed Signed Facebook CLA label Mar 19, 2026
@netlify

netlify Bot commented Mar 19, 2026 •

Copy link
Copy Markdown

✅ [V2]

Name Link
🔨 Latest commit bd034da
🔍 Latest deploy log https://app.netlify.com/projects/docusaurus-2/deploys/6a8c75f5bba356000726a99a
😎 Deploy Preview https://deploy-preview-11821--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@slorber slorber added the pr: bug fix This PR fixes a bug in a past release. label Mar 20, 2026

@slorber slorber left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't work in its current state due to escaping

Remember that generating a description from your content is a best-effort and imperfect heuristic: in any case, it's possible to write a tailor-made description front matter attribute to override the default we generate.

https://docusaurus.io/docs/markdown-features/head-metadata#markdown-page-description

I'm not sure this qualifies as a bug, but I'm open to improving our heuristic with the proposed change. Please add a test file in _dogfooding so that we can validate the change easily in the deploy preview

// Remove inline links.
.replace(/\[(?<alt>.*?)\][[(].*?[\])]/g, '$1')
// Remove inline code.
.replace(/`(?<text>.+?)`/g, '$1')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand why you moved this to the top: to escape tags before HTML tags get removed

Unfortunately, escaping doesn't work, so one solution that could work would be to use marker tags for < and > found in inline code blocks: you could replace these markers with their former < > values after having removed the HTML tags

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've redone the PR but using the markers approach as you suggested. Please let me know if it's not what you had in mind!

(More details in my commit message!)

themavik

This comment was marked as spam.

@SethFalco SethFalco changed the title fix: ignore html tags in inline code syntax fix(metadata): preserve MDX special symbols in inline code syntax Aug 2, 2026
@SethFalco
SethFalco force-pushed the metadata branch 2 times, most recently from a94f7e8 to d7edc0b Compare August 2, 2026 01:29
@SethFalco
SethFalco requested a review from slorber August 2, 2026 01:50
In Markdown/MDX, any special characters between inline code should be displayed
literally. The problem at hand was HTML tags, but this would apply to
underscores, colons, etc. as well.

The description was being mangled before, for example:
"… of `<hn>` tags for headings." → "… of `` tags for headings."

Now we correctly set the description:
"… of <hn> tags for headings." → "… of <hn> tags for headings."

It might've be better if we parsed the content character by character, and
just skipped the pointer to after the inline code when found, but that'd be a
drastic change for little benefit. Instead, I took the marker approach
proposed by Sébastien Lorber—using U+FFFE and U+FFFF. I settled on them since
they are "not characters" so we shouldn't encounter them organically.

See: https://en.wikipedia.org/wiki/Specials_(Unicode_block)
SethFalco added a commit to svg/svgo.dev that referenced this pull request Aug 15, 2026
In Markdown/MDX, any special characters between inline code should be displayed
literally. The problem at hand was HTML tags, but this would apply to
underscores, colons, etc. as well.

The description was being mangled before, for example:
"… of `<hn>` tags for headings." → "… of `` tags for headings."

Now we correctly set the description:
"… of <hn> tags for headings." → "… of <hn> tags for headings."

It might've be better if we parsed the content character by character, and
just skipped the pointer to after the inline code when found, but that'd be a
drastic change for little benefit. Instead, I took the marker approach
proposed by Sébastien Lorber—using U+FFFE and U+FFFF. I settled on them since
they are "not characters" so we shouldn't encounter them organically.

See: https://en.wikipedia.org/wiki/Specials_(Unicode_block)

I've opened a PR upstream to fix this. This can be removed when/if it's
merged in Docusaurus:
meta/docusaurus#11821
@slorber slorber added the Argos Add this label to run UI visual regression tests. See argos.yml GH action. label Aug 23, 2026
@argos-ci

argos-ci Bot commented Aug 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
screenshots (Inspect) 👍 Approved by Sébastien Lorber 45 changed, 1 added Aug 24, 2026, 4:54 PM
text-snapshots (Inspect) 👍 Approved by Sébastien Lorber 3 changed Aug 24, 2026, 4:54 PM

@slorber slorber left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks

I just made the impl a bit more robust and efficient, also handling {} inline code blocks but the logic is kind-of the same as before

# Our website should build even with limited memory
# See https://github.com/facebook/docusaurus/pull/10590
NODE_OPTIONS: '--max-old-space-size=250'
NODE_OPTIONS: '--max-old-space-size=300'

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated but needed after recent CI changes

@@ -1,4 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated but needed after recent copyright changes

@slorber

slorber commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

My new text snapshot regression tooling also caught 3 cases on our website impacted by this change in a positive way 👍 (we had bad descriptions before):

https://app.argos-ci.com/meta-open-source/docusaurus/builds/1903/422242813

CleanShot 2026-08-24 at 18 02 38@2x

@slorber
slorber merged commit 27de99d into meta:main Aug 24, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Argos Add this label to run UI visual regression tests. See argos.yml GH action. CLA Signed Signed Facebook CLA pr: bug fix This PR fixes a bug in a past release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants