-
Notifications
You must be signed in to change notification settings - Fork 4
Rebuild css-props page for Docusaurus V3 #41
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
Rebuild css-props page for Docusaurus V3 #41
Conversation
This means we can remove chmod +x from GitHub Action workflows
This means we can run `make --always-make` without an error if `output/` already exists
- removes docs/css-props.md from .gitignore - imports css-props React page into css-props.md MDX page - uses dangerouslySetInnerHTML to import HTML directly into React instead of using MDX to render JSX - updates Makefile to build css-props page - moves css-props page intro from table.xsl to src/pages/css-props/index.js as JSX, adding JSX spaces, removing a <p> wrapping a <ul> (invalid nesting), and escaping curly braces - adds git-tracked src/pages/css-props/_cssPropsHtml.js so we can see diffs whenever the build process changes - escapes octal sequence in properties.xml near -prince-text-replace
We no longer use htmltojsx to convert HTML to JSX and render within MDX. Instead, we set HTML directly in a React component. This package also did not work without patching on macOS due to line ending issues so if we wanted to keep it, it would be ideal to commit a patch to work cross-platform for development.
Ensure every contributor to the repo has the same dependencies installed
Wow, impressive work! I'm curious about the precise escaping we need to respect in properties.xml now, are there going to be problems with any \ character? We might want to document that in the file itself 🤔 |
Thank you, fantastic work, looks very convincing. |
@mikeday Good idea documenting the precise escaping needed in the file itself. Since the content will appear in a JavaScript template literal, escaping would be required to write a literal backslash ( That said, I realised we could use |
This PR aims to change the approach to the
css-props
page to avoid converting HTML to JSX and instead use HTML directly in a React page. It also updates GitHub actions and build steps.The main commit makes these changes affecting the
css-props
page itself:docs/css-props.md
from.gitignore
css-props
React page intocss-props.md
MDX pagedangerouslySetInnerHTML
to import HTML directly into React instead of using MDX to render JSX — even though it says "dangerous", the content is entirely within our control and does not include unsanitised, nefarious user-crafted HTML so it should be safe to use without risking cross-site scripting vulnerabilitiescss-props
pagecss-props
page intro fromtable.xsl
(as XSL) tosrc/pages/css-props/index.js
(as JSX):{" "}
to ensure spaces don't collapse<p>
wrapping a<ul>
, which caused invalid nesting, which caused a "hydration error"{"{"}
to avoid the content within curly braces being treated as expressionssrc/pages/css-props/_cssPropsHtml.js
so we can see diffs whenever the build process changesproperties.xml
near-prince-text-replace
e.g. changing\017F
to\\017F
in our source content so that it doesn't break JSXFor future content changes to
properties.xml
, we will need to continue to escape octal sequences. If we don't, the Docusaurus dev server will break and let us know where there are unescaped octal sequences, which is good because we won't miss any issues and we'll be able to easily find and fix them.There are 2 giant file changes that make this PR slightly annoying to review:
src/pages/css-props/index.js
, which deletes 20k lines of generated markup and is now replaced<div dangerouslySetInnerHTML={{ __html: cssPropsHtml }}></div>
, but the new behaviour of the component is worth looking at. For review, I suggest leaving it collapsed on GitHub and just opening the new file locally to read it.src/pages/css-props/_cssPropsHtml.js
, which adds the generated markup. I think it's worth git-tracking this file so we can see the impact of build changes but could be persuaded otherwise. It looks a bit like this:This PR makes some other related changes:
properties/Makefile
instead of duplicating all the build steps in multiple places. This code assumes that the GitHub actions image runner hasmake
installed. It also changeswebsite/properties/
tosrc/properties/
, etc.htmltojsx
package, which is now unusedyarn.lock
file so that every contributor to the repo has the same dependencies installedchmod +x
so we can removechmod +x from GitHub Action workflows
(and theproperties/Makefile
works locally on my machine without changes)-p
tomkdir -p output
inproperties/Makefile
so we can runmake --always-make
without an error ifoutput/
already existsThis PR does NOT yet include changes needed to migrate the last of the
shiftWindow.js
behaviour from vanilla JavaScript to modern React code to open/close CSS property sections on change of URL hash. I'd like to do that on a subsequent PR (to keep the scope of this one down) but if it's better to have the CSS props page in a more final working state, let me know.The thinking behind the approach to using HTML (specifically: XML, XSLT, HTML, and
dangerouslySetInnerHTML
):properties.xml
file) and Docusaurus using React/JSX, trying to convert the HTML to JSX and preserve the spacing as intended would be tricky.htmltojsx
, and JSX in MDX:<p>
and one introduced by MDX on new line breaks), which produces in invalid HTML. That is generally not ideal and also results in Docusaurus "hydration errors" where the statically rendered markup does not match "hydrated" markup on first render in the browser.Besides the standard -prince- prefix, Prince also acceptsprince- as a vendor prefix for Prince-specific CSS properties.
andAlso, Prince requires background-origin andbackground-clip to be adjacent.
class
toclassName
,{
to{
, and so on for every possible new content that might not be valid JSX, ortable.xsl
file. I also haven't found any libraries for this that seem reliable or maintained.Other miscellaneous notes:
htmltojsx
:--silent
to theyarn run htmltojsx
step to avoid needing to remove text from the result in the next step of the Makefile (which incidentally also broke on mac because ofsed -i
differences)