Skip to content

Content Editor: Add a basic URL resolver to client-side renderer

Enrique Alcántara requested to merge content-editor/add-basic-url-resolver into master

What does this MR do and why?

NOTICE: This MR is behind the preserve_unchanged_markdown feature flag.

This MR implements a basic URL resolver function for the Markdown deserializer in the Content Editor. What do I mean by URL resolver? The Markdown deserializer takes Markdown as input and produces a ProseMirror document as output. When the user defines a Markdown link or image using a relative asset URL, for example:

[foo](bar.png)

The Markdown deserializer needs to resolve bar.png to its absolute URL which could be https://gitlab.com/bar.png. There are several to do this:

  • We allow referencing repository files in Markdown without providing the file’s absolute URL, for example, [README](readme.md) will become a full README.md. The URL resolution mechanism happens in the server-side Markdown renderer.
  • Uploading an attachment generates a relative URL and the server-side Markdown renderer transforms this relative URL into an absolute URL that points to the actual resource in a CDN.

This MR is a starting point to implement resolving URLs in the web browser instead of the backend. It introduces a transform API that allows targeting all the href and src attributes on every element of a Markdown document. We will implement a correct URL resolution algorithm in a follow-up MR.

Screenshots or screen recordings

See validation instructions.

How to set up and validate locally

  • Enable the preserve_unchanged_markdown feature flag.
  • Create or edit a Wiki page.
  • Enter the following Markdown snippet in the Classic Markdown Editor [foo](foo.png)
  • Switch to the "Rich Text" mode.
  • You will see that the foo.png URL is transformed to [origin]/foo.png when checking the DOM elements in the web inspector. The canonical src allows us to display the original URL in the link editor.

MR acceptance checklist

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

Edited by Enrique Alcántara

Merge request reports