debian-mirror-gitlab/app/assets/javascripts/behaviors/markdown/marks/math.js

43 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-03-02 22:35:43 +05:30
/* eslint-disable class-methods-use-this */
import { defaultMarkdownSerializer } from 'prosemirror-markdown';
2021-03-11 19:13:27 +05:30
import { Mark } from 'tiptap';
2020-03-13 15:44:24 +05:30
import { HIGHER_PARSE_RULE_PRIORITY } from '../constants';
2019-03-02 22:35:43 +05:30
// Transforms generated HTML back to GFM for Banzai::Filter::MathFilter
export default class MathMark extends Mark {
get name() {
return 'math';
}
get schema() {
return {
parseDOM: [
// Matches HTML generated by Banzai::Filter::MathFilter
{
tag: 'code.code.math[data-math-style=inline]',
2020-03-13 15:44:24 +05:30
priority: HIGHER_PARSE_RULE_PRIORITY,
2019-03-02 22:35:43 +05:30
},
// Matches HTML after being transformed by app/assets/javascripts/behaviors/markdown/render_math.js
{
tag: 'span.katex',
contentElement: 'annotation[encoding="application/x-tex"]',
},
],
toDOM: () => ['code', { class: 'code math', 'data-math-style': 'inline' }, 0],
};
}
get toMarkdown() {
return {
escape: false,
open(state, mark, parent, index) {
return `$${defaultMarkdownSerializer.marks.code.open(state, mark, parent, index)}`;
},
close(state, mark, parent, index) {
return `${defaultMarkdownSerializer.marks.code.close(state, mark, parent, index)}$`;
},
};
}
}