debian-mirror-gitlab/app/assets/javascripts/notebook/cells/output/latex.vue

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

53 lines
1.2 KiB
Vue
Raw Normal View History

2021-03-08 18:12:59 +05:30
<script>
2023-03-04 22:38:38 +05:30
import SafeHtml from '~/vue_shared/directives/safe_html';
2021-03-08 18:12:59 +05:30
import 'mathjax/es5/tex-svg';
import Prompt from '../prompt.vue';
export default {
name: 'LatexOutput',
components: {
Prompt,
},
2021-12-11 22:18:48 +05:30
directives: {
SafeHtml,
},
2021-03-08 18:12:59 +05:30
props: {
count: {
type: Number,
required: true,
},
rawCode: {
type: String,
required: true,
},
index: {
type: Number,
required: true,
},
},
computed: {
code() {
// MathJax will not parse out the inline delimeters "$$" correctly
// so we remove them from the raw code itself
const parsedCode = this.rawCode.replace(/\$\$/g, '');
const svg = window.MathJax.tex2svg(parsedCode);
// NOTE: This is used with `v-html` and not `v-safe-html` due to an
// issue with dompurify stripping out xlink attributes from use tags
return svg.outerHTML;
},
},
2021-12-11 22:18:48 +05:30
safeHtmlConfig: {
// to support SVGs and custom tags for mathjax
ADD_TAGS: ['use', 'mjx-container', 'mjx-tool', 'mjx-status', 'mjx-tip'],
},
2021-03-08 18:12:59 +05:30
};
</script>
<template>
<div class="output">
<prompt type="Out" :count="count" :show-output="index === 0" />
2021-12-11 22:18:48 +05:30
<div ref="maths" v-safe-html:[$options.safeHtmlConfig]="code"></div>
2021-03-08 18:12:59 +05:30
</div>
</template>