Skip to content

Set up initial GFM parser

Enrique Alcántara requested to merge setup-initial-parser into master

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?

  1. Remark parses Markdown source and produces a Abstract Syntax Tree called mdast (see use(remark) statement). You can explore the shape of an mdast AST in: https://astexplorer.net/#/gist/f7fcafd451c200a0f1c2fc2f91fc3e2d/latest
  2. We transform the mdast AST into a hast AST to process HTML embedded inside Markdown using the remark-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.
  3. We process the hast AST again to convert raw HTML into valid nodes within the AST. We use the rehype-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.

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.

Relates to #355785 (closed)

Edited by Enrique Alcántara

Merge request reports

Loading