@atlaskit/editor-plugin-paste
Version:
Paste plugin for @atlaskit/editor-core
41 lines (40 loc) • 1.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getMarkdownSliceViaGfm = getMarkdownSliceViaGfm;
var _monitoring = require("@atlaskit/editor-common/monitoring");
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 `platform_editor_paste_as_md_use_gfm` is enabled AND 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, wrapBareUrls) {
// The injected GFM converter enables tables, task lists, and strikethrough
// individually, but does not enable the GFM autolink-literal extension. In
// the treatment, wrap bare URLs in CommonMark autolink syntax so the card
// plugin receives a link mark to resolve. Preserve the current behavior in
// control while the fix rolls out.
var escapedTextInput = (0, _index.escapeBackslashAndLinksExceptCodeBlock)(text, {
skipLinkEscaping: !wrapBareUrls
});
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, _monitoring.logException)(e instanceof Error ? e : new Error(String(e)), {
location: 'editor-plugin-paste/getMarkdownSlice'
});
}
return undefined;
}