Skip to content

fix: ignore html tags in inline code syntax#11821

Open
SethFalco wants to merge 1 commit intofacebook:mainfrom
SethFalco:metadata
Open

fix: ignore html tags in inline code syntax#11821
SethFalco wants to merge 1 commit intofacebook:mainfrom
SethFalco:metadata

Conversation

@SethFalco
Copy link
Contributor

@SethFalco SethFalco commented Mar 19, 2026

In Markdown, any special characters between inline code should be displayed literally. Before if XML tags were shown inside inline code, they were removed because they were HTML tags, but this is wrong. XML tags should only be removed if they're outside of inline code blocks.

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 value in future.

Test Plan

The unit tests should suffice.

I can also demonstrate this works through a page on Docusaurus.io that was affected by this. This is easiest to visualize through Open Graph embeds.

Production

image

This Branch

image

Test links

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

Related issues/PRs

In Markdown, any special characters between inline code should be displayed
literally. Before if XML tags were shown inside inline code, they were removed
because they were HTML tags, but this is wrong. XML tags should only be removed
if they're outside of inline code blocks.
@meta-cla meta-cla bot added the CLA Signed Signed Facebook CLA label Mar 19, 2026
@netlify
Copy link

netlify bot commented Mar 19, 2026

[V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit a9f836b
🔍 Latest deploy log https://app.netlify.com/projects/docusaurus-2/deploys/69bc7de9de25c60008dabb8f
😎 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.

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
Copy link
Collaborator

@slorber slorber left a comment

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

const cleanedLine = fileLine
// Remove inline code.
.replace(/`(?<text>.+?)`/g, (_match, p1) => {
return p1.replaceAll('<', '&lt;').replaceAll('>', '&gt;');
Copy link
Collaborator

Choose a reason for hiding this comment

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

You are not supposed to escape the string here; it's done automatically later in the process, if needed (not the case for metadata)

Otherwise, you end up with this:

Image

And crawlers see this:

Image

}

const cleanedLine = fileLine
// Remove inline code.
Copy link
Collaborator

Choose a reason for hiding this comment

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

comment is wrong, we don't remove them anymore but we unwrap them

// Remove inline links.
.replace(/\[(?<alt>.*?)\][[(].*?[\])]/g, '$1')
// Remove inline code.
.replace(/`(?<text>.+?)`/g, '$1')
Copy link
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

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

Labels

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

2 participants