@atlaskit/editor-plugin-paste
Version:
Paste plugin for @atlaskit/editor-core
32 lines (31 loc) • 1.37 kB
JavaScript
import { logException } from '@atlaskit/editor-common/monitoring/error';
import { Slice } from '@atlaskit/editor-prosemirror/model';
import { escapeBackslashAndLinksExceptCodeBlock } from './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.
*/
export 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 = escapeBackslashAndLinksExceptCodeBlock(text);
try {
var doc = schema.nodes.doc.createAndFill({}, markdownToPmConverter({
markdown: escapedTextInput,
schema: schema
}));
if (doc && doc.content) {
return new Slice(doc.content, openStart, openEnd);
}
} catch (e) {
void logException(e instanceof Error ? e : new Error(String(e)), {
location: 'editor-plugin-paste/getMarkdownSlice'
});
}
return undefined;
}