-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: reduce usage of markdown splicing #690
Conversation
Deploying electron-website with Cloudflare Pages
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing these! 🙇♀️
This is a tangent, but that feels like a good candidate that we might be able to fix upstream with a linting rule. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Partial review, just wanted to throw the requested changes on now since it's a security-related change. Will finish reviewing the rest tomorrow.
7b260ce
to
eceb5ab
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM, I'm not able to find any regressions. Cases checked:
- ✅ Inlines
- ✅ Labels render
- ✅ Hovers on referenced structures work
- ✅ Nested inlines unfurl correctly
- ✅ Hover previews
- ✅ First header renders correctly
- ✅ Labels render
- ✅ Referenced structures are plain links and not previews on previews
Leaving two comments where I think we should add more detailed comments for posterity (you did a great job of commenting other parts of the code and improving the existing comments!), then ready to merge!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great refactor!
Fixes #691
Fixes #682
Background
This pull request simplifies some of the pre-processing steps that we use to transform the raw documentation in
electron/electron
into the rendered HTML on the website.The first pre-processing step involves making changes to the raw Markdown files on disk by using regex-based replacement in
yarn pre-build
. The replacements made are crude but necessary for edge cases that can't be parsed by Docusaurus' MDX parser.For example, MDX's usage of JSX means that
<img>
tags need to be self-closing, while they don't need to be according to the HTML spec:website/scripts/tasks/md-fixers.ts
Lines 86 to 97 in 9487f62
Problem
The
fixLinks
function attempts to normalize in the documentation by storing a hashmap of each file and its respective Markdown string contents. It then replaces every single Markdown link with the normalized link matching the file name. This storage mechanism causes problems when two or more documents have the same name under different paths (e.g. API documentation and a tutorial for some exported module).This fixer function was added early in the website's development cycle (#3) and is useless for the vast majority of links in the docs.
However,
fixLinks
is necessary to get another one of our Markdown hacks working. Namely,inlineApiStructures
adds the ability to insert API structures in other documents using an?inline
Markdown link.This situation leaves us at an impasse where we have broken links in our docs with
fixLinks
enabled, but we can't fix the problem without breaking links ininlineApiStructures
.Solution
This PR tackles the problem by migrating the inlining process to Docusaurus' MDX rendering pipeline, which parses the raw Markdown into an AST and converts it into HTML.
At a high level, we already have multiple plugins that manipulate ASTs, one of which (
api-structure-previews
) stores API structure content in memory to render hover previews on API pages.This PR reuses this architecture to separately inline the appropriate API structure content in the AST and removes
fixLinks
andinlineApiStructures
entirely.Additional notes
api-structure-previews
now stores the MDAST for each structure instead of the raw string to facilitate inlining.react-markdown
library anymore.dangerouslySetInnerHTML
./docs/
directory. It switches all normalized links to their raw counterparts, which still work. Docusaurus does not throw any broken link errors on build times.