Welcome to mirror list, hosted at ThFree Co, Russian Federation.

math_inline.js « extensions « content_editor « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b95ef10550fc6881fb3c530915c0dba405cc1599 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { Mark, markInputRule } from '@tiptap/core';
import { __ } from '~/locale';
import { PARSE_HTML_PRIORITY_HIGH } from '../constants';

export default Mark.create({
  name: 'mathInline',

  parseHTML() {
    return [
      // Matches HTML generated by Banzai::Filter::MathFilter
      {
        tag: 'code.math[data-math-style=inline]',
        priority: PARSE_HTML_PRIORITY_HIGH,
      },
      // Matches HTML after being transformed by app/assets/javascripts/behaviors/markdown/render_math.js
      {
        tag: 'span.katex',
        contentElement: 'annotation[encoding="application/x-tex"]',
      },
    ];
  },

  renderHTML({ HTMLAttributes }) {
    return [
      'code',
      {
        title: __('Inline math'),
        'data-toggle': 'tooltip',
        class: 'gl-inset-border-1-gray-400',
        ...HTMLAttributes,
      },
      0,
    ];
  },

  addInputRules() {
    const inputRegex = /(?:^|\s)\$`([^`]+)`\$$/gm;

    return [markInputRule({ find: inputRegex, type: this.type })];
  },
});