@atlaskit/editor-wikimarkup-transformer
Version:
Wiki markup transformer for JIRA and Confluence
36 lines • 1.03 kB
JavaScript
import { commonMacro } from './common-macro';
export var adfMacro = function adfMacro(_ref) {
var input = _ref.input,
position = _ref.position,
schema = _ref.schema,
context = _ref.context;
return commonMacro(input.substring(position), schema, {
keyword: 'adf',
paired: true,
context: context,
rawContentProcessor: rawContentProcessor
});
};
var rawContentProcessor = function rawContentProcessor(_rawAttrs, rawContent, length, schema, _context) {
try {
var json = JSON.parse(rawContent);
var node = schema.nodeFromJSON(json);
return {
type: 'pmnode',
nodes: [node],
length: length
};
} catch (_e) {
var textContent = "Invalid ADF Macro: ".concat(rawContent);
var textNode = rawContent.length ? schema.text(textContent) : undefined;
var codeBlock = schema.nodes.codeBlock;
var _node = codeBlock.create({
language: undefined
}, textNode);
return {
type: 'pmnode',
nodes: [_node],
length: length
};
}
};