Content Editor: Skip unknown tags in the client-side parser

What does this MR do and why?

It changes how the client-side Markdown renderer used by the Content Editor handles HTML tags that aren’t explicitly supported. The client-sider Markdown renderer maps a ProseMirror a HAST AST that represents an HTML document to a ProseMirror document by reading a mapping configuration:

blockquote: { type: 'block', selector: 'blockquote' },
paragraph: { type: 'block', selector: 'p' },
listItem: {
  type: 'block',
  wrapInParagraph: true,
  selector: (hastNode) => hastNode.tagName === 'li' && !hastNode.properties.className,
  processText: (text) => text.trimRight(),
}

If the renderer finds an HTML tag that isn’t explicitly specified in the configuration, it raises an exception. This is a problematic behavior because you can use any ASCII string as a valid HTML tag. We change that behavior to just skip the unknown tags and continue mapping the rest of the AST.

Screenshots or screen recordings

I highly recommend testing this locally using the following examples:

<style
  type="text/css">
h1 {color:red;}

p {color:blue;}
</style>
<Warning>
*bar*
</Warning>
<script>
window.location = 'anothersite';
</script>

How to set up and validate locally

  1. Enable the preserve_unchanged_markdown feauture flag in your local environment
  2. Create or edit a Wiki page
  3. Insert any of the examples above in the Classic Markdown Editor and switch to the Content Editor clicking the "Rich text" button.
  4. The Content Editor should appear empty because those HTML tags aren’t supported.

MR acceptance checklist

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

Related to #365292 (closed)

Edited by Enrique Alcántara

Merge request reports

Loading