UNPKG

@atlaskit/editor-plugin-paste

Version:

Paste plugin for @atlaskit/editor-core

37 lines (36 loc) • 1.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getMarkdownSliceViaGfm = getMarkdownSliceViaGfm; var _error = require("@atlaskit/editor-common/monitoring/error"); var _model = require("@atlaskit/editor-prosemirror/model"); var _index = require("./index"); /** * Convert plain-text markdown to a ProseMirror Slice using the GFM converter. * * Only called when a `markdownToPmConverter` is provided. Returns `undefined` if the converter * throws or produces an empty document — the caller will propagate `undefined` * without falling back to the legacy MarkdownTransformer. */ function getMarkdownSliceViaGfm(text, schema, openStart, openEnd, markdownToPmConverter) { // The injected GFM converter enables tables, task lists, and strikethrough // individually, but does not enable the GFM autolink-literal extension. // Wrap bare URLs in CommonMark autolink syntax so the card plugin receives // a link mark to resolve. var escapedTextInput = (0, _index.escapeBackslashAndLinksExceptCodeBlock)(text); try { var doc = schema.nodes.doc.createAndFill({}, markdownToPmConverter({ markdown: escapedTextInput, schema: schema })); if (doc && doc.content) { return new _model.Slice(doc.content, openStart, openEnd); } } catch (e) { void (0, _error.logException)(e instanceof Error ? e : new Error(String(e)), { location: 'editor-plugin-paste/getMarkdownSlice' }); } return undefined; }