Skip to content

Support defining text nodes directly in the root document

Enrique Alcántara requested to merge fix-direct-text-nodes-in-document into master

What does this MR do and why?

  • NOTICE: This change is behind a the preserve_unchanged_markdown feature flag.
  • Context: This change is part of a larger effort to preserve unchanged Markdown in the Content Editor. For this effort, we need to support client-side parsing of Markdown content.

This MR fixes a bug in the Content Editor’s client-side Markdown parser where text nodes that are direct children of the root document make the AST to ProseMirror document fail. The bug is fixed by wrapping those text nodes in a paragraph. This is what a text node looks like when it is a direct child of the root node:

{
  "type": "root",
  "children": [
    {
      "type": "html",
      "value": "<i class=\"foo\">\n  *bar*\n</i>",
      "position": {
        "start": {
          "line": 1,
          "column": 1,
          "offset": 0
        },
        "end": {
          "line": 3,
          "column": 5,
          "offset": 28
        }
      }
    }
  ],
}

That AST represents the Markdown snippet in example 164 of the Commonmark spec: https://spec.commonmark.org/0.30/#example-164

Screenshots or screen recordings

Before After
Before the fix demo After the fix demo

How to set up and validate locally

  1. Edit or create a Wiki page
  2. Enter the following Markdown snippet in the Classic Markdown Editor. The example comes from the Markdown spec: https://spec.commonmark.org/0.30/#example-164
    <i class="foo">
      *bar*
    </i>
  3. Switch to rich text mode. You should see the same result as the screenshots above.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Enrique Alcántara

Merge request reports