Set up initial GFM parser
What does this MR do and why?
Sets up a basic client-side Markdown parser based on unified, remark, and rehype.
The parser exposes a function named render
that accepts two parameters: The markdown
to parse and a renderer
function that transforms the AST produced by remark
and rehype
into another format.
How does the parsing pipeline works?
- Remark parses Markdown source and produces a Abstract Syntax Tree called
mdast
(seeuse(remark)
statement). You can explore the shape of an mdast AST in: https://astexplorer.net/#/gist/f7fcafd451c200a0f1c2fc2f91fc3e2d/latest - We transform the mdast AST into a
hast
AST to process HTML embedded inside Markdown using theremark-rehype
package.hast
is an Abstract Syntax Tree for the HTML language. We allow any HTML at this point, but before this change is used in production, we will apply html sanitization measures. - We process the
hast
AST again to convert raw HTML into valid nodes within the AST. We use therehype-raw
package for this purpose.
Where can I see more about this effort?
This MR is part of a larger effort to change the Content Editor’s Markdown parser and renderer. The goal is preserving parts of a Markdown document that the user didn’t change using the Content Editor.
- You can track the overall effort in: &7256
- You can read about the architectural decisions in: https://docs.google.com/document/d/1aYfWIyavQAK_rJw23YMFZlPBRRAzTupXdGR0CUanmY4/edit
Screenshots or screen recordings
This MR doesn’t introduce user-facing changes.
How to set up and validate locally
We can’t test these changes through the application yet.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Relates to #355785 (closed)