UNPKG

@atlaskit/editor-wikimarkup-transformer

Version:

Wiki markup transformer for JIRA and Confluence

39 lines 884 B
import { commonMacro } from './common-macro'; export const adfMacro = ({ input, position, schema, context }) => { return commonMacro(input.substring(position), schema, { keyword: 'adf', paired: true, context, rawContentProcessor }); }; const rawContentProcessor = (_rawAttrs, rawContent, length, schema, _context) => { try { const json = JSON.parse(rawContent); const node = schema.nodeFromJSON(json); return { type: 'pmnode', nodes: [node], length }; } catch (_e) { const textContent = `Invalid ADF Macro: ${rawContent}`; const textNode = rawContent.length ? schema.text(textContent) : undefined; const { codeBlock } = schema.nodes; const node = codeBlock.create({ language: undefined }, textNode); return { type: 'pmnode', nodes: [node], length }; } };