UNPKG

@curvenote/schema

Version:

Schema and markdown parser for @curvenote/editor

45 lines 1.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.toTex = exports.toMarkdown = exports.mathNoDisplay = void 0; const types_1 = require("./types"); const math = { group: types_1.NodeGroups.inline, // Content can have display elements inside of it for dynamic equations content: `(${types_1.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`); }, }; exports.mathNoDisplay = Object.assign(Object.assign({}, math), { content: `${types_1.NodeGroups.text}*` }); const toMarkdown = (state, node) => { state.write('$'); state.text(node.textContent, false); state.write('$'); }; exports.toMarkdown = toMarkdown; const toTex = (state, node) => { state.write('$'); // The latex escaping happens in the serializer state.renderInline(node); state.write('$'); }; exports.toTex = toTex; exports.default = math; //# sourceMappingURL=math.js.map