Commit 6cd11c32 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch '19397-LaTeX-math-syntax-IPython-notebooks' into 'master'

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

Closes #19397

See merge request gitlab-org/gitlab!19533
parents 804fc9af fcc2dbac
<script> <script>
/* global katex */
import marked from 'marked'; import marked from 'marked';
import sanitize from 'sanitize-html'; import sanitize from 'sanitize-html';
import katex from 'katex';
import Prompt from './prompt.vue'; import Prompt from './prompt.vue';
const renderer = new marked.Renderer(); const renderer = new marked.Renderer();
...@@ -70,7 +70,6 @@ renderer.paragraph = t => { ...@@ -70,7 +70,6 @@ renderer.paragraph = t => {
}; };
marked.setOptions({ marked.setOptions({
sanitize: true,
renderer, renderer,
}); });
...@@ -87,9 +86,66 @@ export default { ...@@ -87,9 +86,66 @@ export default {
computed: { computed: {
markdown() { markdown() {
return sanitize(marked(this.cell.source.join('').replace(/\\/g, '\\\\')), { return sanitize(marked(this.cell.source.join('').replace(/\\/g, '\\\\')), {
allowedTags: false, // allowedTags from GitLab's inline HTML guidelines
// https://docs.gitlab.com/ee/user/markdown.html#inline-html
allowedTags: [
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'h7',
'h8',
'br',
'b',
'i',
'strong',
'em',
'a',
'pre',
'code',
'img',
'tt',
'div',
'ins',
'del',
'sup',
'sub',
'p',
'ol',
'ul',
'table',
'thead',
'tbody',
'tfoot',
'blockquote',
'dl',
'dt',
'dd',
'kbd',
'q',
'samp',
'var',
'hr',
'ruby',
'rt',
'rp',
'li',
'tr',
'td',
'th',
's',
'strike',
'span',
'abbr',
'abbr',
'summary',
],
allowedAttributes: { allowedAttributes: {
'*': ['class'], '*': ['class', 'style'],
a: ['href'],
img: ['src'],
}, },
}); });
}, },
...@@ -105,6 +161,15 @@ export default { ...@@ -105,6 +161,15 @@ export default {
</template> </template>
<style> <style>
/*
Importing the necessary katex stylesheet from the node_module folder rather
than copying the stylesheet into `app/assets/stylesheets/vendors` for
automatic importing via `app/assets/stylesheets/application.scss`. The reason
is that the katex stylesheet depends on many fonts that are in node_module
subfolders - moving all these fonts would make updating katex difficult.
*/
@import '~katex/dist/katex.min.css';
.markdown .katex { .markdown .katex {
display: block; display: block;
text-align: center; text-align: center;
......
...@@ -49,7 +49,7 @@ describe('Markdown component', () => { ...@@ -49,7 +49,7 @@ describe('Markdown component', () => {
}); });
Vue.nextTick(() => { Vue.nextTick(() => {
expect(vm.$el.querySelector('a')).toBeNull(); expect(vm.$el.querySelector('a').getAttribute('href')).toBeNull();
done(); done();
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment