UNPKG

@curvenote/schema

Version:

Schema and markdown parser for @curvenote/editor

101 lines 3.1 kB
import OrderedMap from 'orderedmap'; import { addListNodes } from 'prosemirror-schema-list'; import { NodeGroups } from './types'; import { nodeNames } from '../types'; export const doc = { content: `(${NodeGroups.block} | ${NodeGroups.heading} | ${NodeGroups.top})+`, }; export const docParagraph = { content: 'paragraph', }; export const docComment = { content: `(${NodeGroups.block} | ${NodeGroups.heading} | ${nodeNames.equation})+`, // browsers will completely collapse the node when it's empty `+` is necessary }; export const paragraph = { attrs: {}, content: `${NodeGroups.inline}*`, group: NodeGroups.block, parseDOM: [{ tag: 'p' }], toDOM() { return ['p', 0]; }, attrsFromMyst: () => ({}), toMyst: (props) => ({ type: 'paragraph', children: (props.children || []), }), }; export const blockquote = { attrs: {}, content: `${NodeGroups.block}+`, group: NodeGroups.block, defining: true, parseDOM: [{ tag: 'blockquote' }], toDOM() { return ['blockquote', 0]; }, attrsFromMyst: () => ({}), toMyst: (props) => ({ type: 'blockquote', children: (props.children || []), }), }; /** Horizontal rule */ export const horizontal_rule = { attrs: {}, group: NodeGroups.block, parseDOM: [{ tag: 'hr' }], toDOM() { return ['hr', { class: 'break' }]; }, attrsFromMyst: () => ({}), toMyst: () => ({ type: 'thematicBreak' }), }; export const text = { group: NodeGroups.inline, }; export const hard_break = { attrs: {}, inline: true, group: NodeGroups.inline, selectable: false, parseDOM: [{ tag: 'br' }], toDOM() { return ['br']; }, attrsFromMyst: () => ({}), toMyst: () => ({ type: 'break' }), }; const listNodes = addListNodes(OrderedMap.from({}), `paragraph ${NodeGroups.block}*`, NodeGroups.block); export const ordered_list = listNodes.get('ordered_list'); ordered_list.attrsFromMyst = (token) => ({ order: token.start || 1 }); 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 || []), }); export const bullet_list = listNodes.get('bullet_list'); bullet_list.attrsFromMyst = () => ({}); bullet_list.toMyst = (props) => ({ type: 'list', ordered: false, children: (props.children || []), }); export const list_item = listNodes.get('list_item'); list_item.attrsFromMyst = () => ({}); 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