Skip to content

Allow using pre tag outside of code blocks

What does this MR do and why?

This MR introduces a Pre extension to the Content Editor that allows using this HTML tag outside of code blocks. When the GitLab Markdown API renders a code block, it roughly produces the following HTML:

<pre lang="javascript" class="js-code-block-highlight ...">
  <code>
    console.log('Hello world');
  </code>
</pre>

However, users can use the pre tag in other contexts because the Markdown HTML sanitizer allows it. You can see this in example 118 of the GFM spec:

<table><tr><td>
<pre>
**Hello**,

_world_.
</pre>
</td></tr></table>

We need to distinguish between both the two use cases of the pre tag and render the correct Markdown

Screenshots or screen recordings

Markdown Preview Content Editor
Before Screen_Shot_2022-06-24_at_12.01.19_PM Screen_Shot_2022-06-24_at_12.08.33_PM
After Screen_Shot_2022-06-24_at_12.01.19_PM Screen_Shot_2022-06-24_at_12.02.54_PM

How to set up and validate locally

You can use the Content Editor by editing a Wiki page in your local environment. Copy the following Markdown snippet in the Classic Markdown editor:

<table><tr><td>
<pre>
**Hello**,

_world_.
</pre>
</td></tr></table>

Then switch to the content editor clicking the "Edit rich text" button. You should see the results described in 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.

Related to #365292 (closed)

Edited by Enrique Alcántara

Merge request reports