@curvenote/schema
Version:
Schema and markdown parser for @curvenote/editor
40 lines • 1.33 kB
JavaScript
import { NodeGroups } from './types';
const math = {
group: NodeGroups.inline,
// Content can have display elements inside of it for dynamic equations
content: `(${NodeGroups.text} | display)*`,
inline: true,
marks: '',
draggable: false,
// The view treat the node as a leaf, even though it technically has content
atom: true,
attrs: {},
toDOM: () => ['r-equation', { inline: '' }, 0],
parseDOM: [
{
tag: 'r-equation[inline]',
},
],
attrsFromMyst: () => ({}),
toMyst: (props) => {
var _a;
if (((_a = props.children) === null || _a === void 0 ? void 0 : _a.length) === 1 && props.children[0].type === 'text') {
return { type: 'inlineMath', value: props.children[0].value || '' };
}
throw new Error(`Math node does not have one child`);
},
};
export const mathNoDisplay = Object.assign(Object.assign({}, math), { content: `${NodeGroups.text}*` });
export const toMarkdown = (state, node) => {
state.write('$');
state.text(node.textContent, false);
state.write('$');
};
export const toTex = (state, node) => {
state.write('$');
// The latex escaping happens in the serializer
state.renderInline(node);
state.write('$');
};
export default math;
//# sourceMappingURL=math.js.map