UNPKG

@curvenote/schema

Version:

Schema and markdown parser for @curvenote/editor

87 lines 2.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.toTex = exports.toMarkdown = void 0; const types_1 = require("./types"); const LINK_BLOCK_CLASS = 'link-block'; const link_block = { attrs: { url: { default: '' }, title: { default: '' }, description: { default: '' }, }, group: types_1.NodeGroups.top, content: `${types_1.NodeGroups.text}*`, selectable: true, draggable: true, atom: true, isolating: true, parseDOM: [ { tag: `div.${LINK_BLOCK_CLASS}`, getAttrs(dom) { const attrs = { url: dom.getAttribute('data-url') || null, title: dom.getAttribute('title') || '', description: dom.textContent || '', }; return attrs; }, }, ], toDOM(node) { const { title, description, url } = node.attrs; return [ 'div', { 'data-url': url || undefined, title, class: LINK_BLOCK_CLASS, }, description, ]; }, attrsFromMyst: (token) => { let description = ''; if (token.children.length && token.children[0].type === 'text') { description = token.children[0].value; } return { url: token.url, title: token.title || '', description, }; }, toMyst: (props) => { return { type: 'linkBlock', url: props['data-url'], title: props.title || undefined, children: (props.children || []), }; }, }; const toMarkdown = (state, node) => { state.ensureNewLine(); state.write(`\`\`\`{link-block} ${node.attrs.url}\n`); if (node.attrs.title) state.write(`:title: ${node.attrs.title}\n`); if (node.attrs.thumbnail) state.write(`:thumbnail: ${node.attrs.thumbnail}\n`); if (node.attrs.description) state.write(`${node.attrs.description}\n`); state.ensureNewLine(); state.write('```'); state.closeBlock(node); }; exports.toMarkdown = toMarkdown; const toTex = (state, node) => { if (node.attrs.title) { state.write(`\\href{${node.attrs.url}}{${node.attrs.title}}`); } else { state.write(`\\url{${node.attrs.url}}`); } }; exports.toTex = toTex; exports.default = link_block; //# sourceMappingURL=linkBlock.js.map