@atlaskit/editor-wikimarkup-transformer
Version:
Wiki markup transformer for JIRA and Confluence
42 lines (41 loc) • 1.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.adfMacro = void 0;
var _commonMacro = require("./common-macro");
var adfMacro = exports.adfMacro = function adfMacro(_ref) {
var input = _ref.input,
position = _ref.position,
schema = _ref.schema,
context = _ref.context;
return (0, _commonMacro.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
};
}
};