Skip to content

Only use backslash escapes in autocomplete when needed

Sean McGivern requested to merge markdown-autocomplete-escaping into master

What does this MR do?

Autocompletion for references happens on the frontend. Those references are turned into actual references on the backend, but only after Markdown processing has happened. That means that if a reference contains a character that Markdown might consume, it won't render correctly. So we need to do some escaping on the frontend.

We have these potential problem characters: https://docs.gitlab.com/ee/user/markdown.html#emphasis

  1. ~ - this is strikethrough, but only when doubled.
  2. _ - used for emphasis, doubled is bold.
  3. * - also used for emphasis, doubled is bold also.
  4. ` - used for code spans, any number works.

We don't need to escape - any more. When it comes to being inside a word:

  1. a~~b~~ -> ab (has strikethrough), so it needs to be escaped everywhere.
  2. a_b_ -> a_b_ (no emphasis, see https://docs.gitlab.com/ee/user/markdown.html#multiple-underscores-in-words), so it only needs to be escaped at the start and end of words.
  3. a*b* -> ab (emphasis), so it needs to be escaped everywhere.
  4. a`b` -> ab (code span), so it needs to be escaped everywhere.

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/45348.

Does this MR meet the acceptance criteria?

Conformity

Performance and testing

Edited by Sean McGivern

Merge request reports