@curvenote/schema
Version:
Schema and markdown parser for @curvenote/editor
107 lines • 3.74 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.list_item = exports.bullet_list = exports.ordered_list = exports.hard_break = exports.text = exports.horizontal_rule = exports.blockquote = exports.paragraph = exports.docComment = exports.docParagraph = exports.doc = void 0;
const orderedmap_1 = __importDefault(require("orderedmap"));
const prosemirror_schema_list_1 = require("prosemirror-schema-list");
const types_1 = require("./types");
const types_2 = require("../types");
exports.doc = {
content: `(${types_1.NodeGroups.block} | ${types_1.NodeGroups.heading} | ${types_1.NodeGroups.top})+`,
};
exports.docParagraph = {
content: 'paragraph',
};
exports.docComment = {
content: `(${types_1.NodeGroups.block} | ${types_1.NodeGroups.heading} | ${types_2.nodeNames.equation})+`, // browsers will completely collapse the node when it's empty `+` is necessary
};
exports.paragraph = {
attrs: {},
content: `${types_1.NodeGroups.inline}*`,
group: types_1.NodeGroups.block,
parseDOM: [{ tag: 'p' }],
toDOM() {
return ['p', 0];
},
attrsFromMyst: () => ({}),
toMyst: (props) => ({
type: 'paragraph',
children: (props.children || []),
}),
};
exports.blockquote = {
attrs: {},
content: `${types_1.NodeGroups.block}+`,
group: types_1.NodeGroups.block,
defining: true,
parseDOM: [{ tag: 'blockquote' }],
toDOM() {
return ['blockquote', 0];
},
attrsFromMyst: () => ({}),
toMyst: (props) => ({
type: 'blockquote',
children: (props.children || []),
}),
};
/** Horizontal rule */
exports.horizontal_rule = {
attrs: {},
group: types_1.NodeGroups.block,
parseDOM: [{ tag: 'hr' }],
toDOM() {
return ['hr', { class: 'break' }];
},
attrsFromMyst: () => ({}),
toMyst: () => ({ type: 'thematicBreak' }),
};
exports.text = {
group: types_1.NodeGroups.inline,
};
exports.hard_break = {
attrs: {},
inline: true,
group: types_1.NodeGroups.inline,
selectable: false,
parseDOM: [{ tag: 'br' }],
toDOM() {
return ['br'];
},
attrsFromMyst: () => ({}),
toMyst: () => ({ type: 'break' }),
};
const listNodes = (0, prosemirror_schema_list_1.addListNodes)(orderedmap_1.default.from({}), `paragraph ${types_1.NodeGroups.block}*`, types_1.NodeGroups.block);
exports.ordered_list = listNodes.get('ordered_list');
exports.ordered_list.attrsFromMyst = (token) => ({ order: token.start || 1 });
exports.ordered_list.toMyst = (props) => ({
type: 'list',
ordered: true,
// This feels like it should be `start: props.order`, but it
// is in fact correct as is since we are grabbing these props
// off the HTML in `convertToMdast`, not the prosemirror node
// https://github.com/ProseMirror/prosemirror-schema-list/blob/master/src/schema-list.js#L17
start: props.start || undefined,
children: (props.children || []),
});
exports.bullet_list = listNodes.get('bullet_list');
exports.bullet_list.attrsFromMyst = () => ({});
exports.bullet_list.toMyst = (props) => ({
type: 'list',
ordered: false,
children: (props.children || []),
});
exports.list_item = listNodes.get('list_item');
exports.list_item.attrsFromMyst = () => ({});
exports.list_item.toMyst = (props) => {
let { children } = props;
if (children && children.length === 1 && children[0].type === 'paragraph') {
children = children[0].children;
}
return {
type: 'listItem',
children: (children || []),
};
};
//# sourceMappingURL=basic.js.map
;