Skip to content

Preserve unchanged Commonmark blocks

Enrique Alcántara requested to merge 359019-preserve-commonmark-markdown into master

What does this MR do and why?

Context: These changes are behind the feature flag preserve_unchanged_markdown

It uses Markdown source maps to preserve parts of a Markdown document that aren’t changed by the user in the Content Editor. Why do we need to do this? In Markdown, you can apply the same format using different syntax, i.e.

Heading 1
===

# Heading 1

**Bold text** or __bold text__ or <strong>bold text</strong>

1. List item 1

1) List item 1

All the examples above represent equivalent formatting elements applied using different syntax. Before this change, the Content Editor couldn’t preserve the original syntax of a Markdown document. This change enables source preservation for a subset of GitLab Flavored Markdown features.

NOTICE: This MR doesn’t implement source preservation for inline elements yet. In other words, if you change a paragraph, the entire paragraph will be re-generated. We will implement an improvement that allows preserving segments of a paragraph.

Screenshots or screen recordings

Before this change After this change
2022-05-06_14.30.22 2022-05-06_14.33.29

How to set up and validate locally

  1. Enable the preserve_unchanged_markdown feature flag.
  2. Edit or create a Wiki page.
  3. Try one of the Markdown examples above where different syntax yield the same result.
  4. When you switch between source and rich text modes, if you don’t change anything in the Content Editor, the original Markdown syntax should be preserved.

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 #359019 (closed)

Edited by Enrique Alcántara

Merge request reports