All files / app/assets/javascripts/content_editor/extensions math_inline.js

100% Statements 4/4
100% Branches 0/0
100% Functions 3/3
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                92x                 2x                         92x   92x      
import { Mark, markInputRule } from '@tiptap/core';
import { __ } from '~/locale';
import { PARSE_HTML_PRIORITY_HIGHEST } from '../constants';
 
export default Mark.create({
  name: 'mathInline',
 
  parseHTML() {
    return [
      {
        tag: 'code.math[data-math-style=inline]',
        priority: PARSE_HTML_PRIORITY_HIGHEST,
      },
    ];
  },
 
  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 })];
  },
});