Repository navigation
fix(metadata): preserve MDX special symbols in inline code syntax - #11821
Conversation
✅ [V2]
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
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.
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') |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!)
a94f7e8 to
d7edc0b
Compare
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)
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
|
The latest updates on your projects. Learn more about Argos notifications ↗︎
|
slorber
left a comment
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
Unrelated but needed after recent CI changes
| @@ -1,4 +1,10 @@ | |||
| <?xml version="1.0" encoding="UTF-8" ?> | |||
| <!-- | |||
There was a problem hiding this comment.
Unrelated but needed after recent copyright changes

Pre-flight checklist
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.
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