Skip to content

Resolve "LaTeX math syntax interpreted as Markdown in IPython notebooks"

What does this MR do?

Resolves issue 19397.

Specifically, mathematical expressions aren't currently being rendered by Katex inside the markdown cells of IPython (aka Jupyter) notebooks. This merge request primarily fixes that.

In addition, I found that the existing code that attempts to render the maths was preventing normal markdown elements (such as links and images) from being rendered - this merge request fixes that too.

It should be noted that Gitlab handles the rendering of markdown inside notebooks differently to other places. Notebook markdown is handled via app/assets/javascripts/notebook/cells/markdown.vue whereas another markdown is handled via app/assets/javascripts/behaviors/markdown/render_gfm.js. I presumed that there was a reason for the notebook specific code and so I decided to adapt markdown.vue instead of trying to figure out a way for the notebooks to connect to render_gfm.js.

The only risks I see in this merge request relate to what html tags and attributes we allow to be processed. Katex requires that style attributes be allowed. I found some reference to Gilab guidelines on HTML sanitization, but it would be good to get a second opinion on the choices I've made for the sanitize-html options.

This is my first merge request into such a big repo, so I apologise in advance if I'm not following protocol properly - in particular, there are many tick boxes below that I'm not sure what to do with.

I began by detailing my investigations into the existing code base in the issue conversation and have now been able to test the ideas using the Gitlab development kit. I've tried to atomise my commits as much as possible and have used the description part of the commit message to justify what I've done. I hope this is in line with Gitlab's conventions.

Screenshots

Currently, this is how Gitab renders markdown inside IPython (aka Jupyter) notebooks:

Screenshot_2019-11-03_at_15.38.47

The code in this merge request fixes not only the equations but links and images that are typical elements of notebook markdown. The results look like the image below:

Screenshot_2019-11-03_at_15.44.02

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team

Closes #19397 (closed)

Merge request reports