UNPKG

@atlaskit/editor-plugin-paste

Version:

Paste plugin for @atlaskit/editor-core

36 lines (35 loc) 1.56 kB
import { logException } from '@atlaskit/editor-common/monitoring'; 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 `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. */ export 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. const escapedTextInput = escapeBackslashAndLinksExceptCodeBlock(text, { skipLinkEscaping: !wrapBareUrls }); try { const doc = schema.nodes.doc.createAndFill({}, markdownToPmConverter({ markdown: escapedTextInput, 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; }