Skip to content

Support bracket-less autolinks in the Content Editor

Enrique Alcántara requested to merge 359013-preserve-gfm-autolinks into master

What does this MR do and why?

It adds support for bracketless autolink generation in the Content Editor.

In Commonmark, URLs surrounded with the < and > characters are converted into HTML links without requiring the Markdown syntax, for example: <https://gitlab.com>. GitHub Flavored Markdown extends autolink support to recognize links even when they are not surrounded by brackets. The following conditions should be met:

Autolinks can also be constructed without requiring the use of < and to > to delimit them, although they will be recognized under a smaller set of circumstances. All such recognized autolinks can only come at the beginning of a line, after whitespace, or any of the delimiting characters *, _, ~, and (.

This MR ensures that the Content Editor doesn’t surround autolinks with brackets if it isn’t necessary.

When does the content editor surround links with brackets?

You need to enable the preserve_unchanged_markdown feature flag to reproduce this scenario. The Content Editor will add brackets if the user defined a link previously using the brackets. We will show a demonstration in the screenshots below.

References

We use some ProseMirror APIs on this Merge Request. I recommend reading the documentation for a better understanding of the code:

Screenshots or screen recordings

Before After
2022-06-07_18.31.39 2022-06-08_14.09.11

How to set up and validate locally

  • Edit or create a Wiki page
  • Insert the following Markdown code snippet in the Classic Markdown Editor
    This is an autolink with modified brackets <https://gitlab.com>
    
    This is an autolink without modified brackets https://gitlab.com
    
    This is an email autolink without modified brackets email@gitlab.com
  • Switch to rich text mode.
  • Edit each paragraph. If you edit the links, remember to always match the link’s text and the link’s URL. Otherwise, it isn’t an autolink 😄.
  • Switch to source mode. You will notice that autolinks do not include brackets or Markdown link syntax because it isn’t necessary.
  • To preserve existing brackets on autolinks, you should enable the preserve_unchanged_markdown feature flag to enable source map support.

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

Edited by Enrique Alcántara

Merge request reports