UNPKG

@curvenote/schema

Version:

Schema and markdown parser for @curvenote/editor

115 lines 3.73 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.toText = exports.textSerializer = void 0; const prosemirror_markdown_1 = require("prosemirror-markdown"); const nodes = __importStar(require("../../nodes")); const clean_1 = require("../clean"); function simpleInlineRender(state, node) { state.renderInline(node); } function simpleBlockRender(state, node) { state.renderInline(node); state.closeBlock(node); } function newLine(state) { state.ensureNewLine(); } function nothing() { // pass } const noMarks = { open: '', close: '', mixable: true, }; exports.textSerializer = new prosemirror_markdown_1.MarkdownSerializer({ text(state, node) { var _a; state.text((0, clean_1.cleanWhitespaceChars)((_a = node.text) !== null && _a !== void 0 ? _a : ''), false); }, paragraph: simpleBlockRender, heading: simpleBlockRender, blockquote: simpleBlockRender, code_block: simpleBlockRender, link_block: simpleBlockRender, footnote: simpleBlockRender, horizontal_rule: newLine, hard_break: newLine, ordered_list(state, node) { const start = node.attrs.order || 1; const maxW = String(start + node.childCount - 1).length; const space = state.repeat(' ', maxW + 2); state.renderList(node, space, (i) => { const nStr = String(start + i); return `${state.repeat(' ', maxW - nStr.length) + nStr}. `; }); }, bullet_list(state, node) { state.renderList(node, ' ', () => `${node.attrs.bullet || '*'} `); }, list_item(state, node) { state.renderInline(node); }, // Presentational image: newLine, iframe: newLine, figure: simpleBlockRender, figcaption: simpleBlockRender, time: nodes.Time.toMarkdown, callout: simpleBlockRender, aside: simpleBlockRender, // Technical math: simpleInlineRender, equation: simpleBlockRender, cite: nodes.Cite.toMarkdown, cite_group: nodes.CiteGroup.toMarkdown, mention: nodes.Mention.toMarkdown, // Tables table: nodes.Table.toGFMMarkdownTable, // Dynamic variable: newLine, display: nodes.Display.toMarkdown, dynamic: nodes.Dynamic.toMarkdown, range: nothing, switch: nothing, button: nothing, }, { em: noMarks, strong: noMarks, link: noMarks, code: noMarks, abbr: noMarks, subscript: noMarks, superscript: noMarks, strikethrough: noMarks, underline: noMarks, }); function toText(doc) { const md = exports.textSerializer.serialize(doc, { tightLists: true }); return md; } exports.toText = toText; //# sourceMappingURL=index.js.map