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

32 lines
1.1 KiB
JavaScript
Raw Normal View History

2022-04-04 11:22:00 +05:30
import { defaultMarkdownSerializer } from '~/lib/prosemirror_markdown_serializer';
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
2022-05-07 20:08:51 +05:30
export default () => ({
name: 'math',
schema: {
parseDOM: [
// Matches HTML generated by Banzai::Filter::MathFilter
{
tag: 'code.code.math[data-math-style=inline]',
priority: HIGHER_PARSE_RULE_PRIORITY,
2019-03-02 22:35:43 +05:30
},
2022-05-07 20:08:51 +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"]',
2019-03-02 22:35:43 +05:30
},
2022-05-07 20:08:51 +05:30
],
toDOM: () => ['code', { class: 'code math', 'data-math-style': 'inline' }, 0],
},
toMarkdown: {
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)}$`;
},
},
});