UNPKG

@atlaskit/editor-wikimarkup-transformer

Version:

Wiki markup transformer for JIRA and Confluence

52 lines (50 loc) 2.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.media = void 0; var media = exports.media = function media(node) { var _context$conversion2; var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, context = _ref.context, parent = _ref.parent; var wikiAttrs = []; // Parent width takes precedence over internal dimension attributes if (parent && parent.attrs.width) { // Parent width is defined in percents wikiAttrs.push("width=".concat(parent.attrs.width, "%")); } else { if (node.attrs.width) { wikiAttrs.push("width=".concat(node.attrs.width)); } if (node.attrs.height) { wikiAttrs.push("height=".concat(node.attrs.height)); } } if (node.attrs.alt) { wikiAttrs.push("alt=\"".concat(node.attrs.alt, "\"")); } if (node.marks.length) { var linkMark = node.marks.find(function (mark) { return mark.type.name === 'link'; }); if (linkMark) { wikiAttrs.push("href=\"".concat(linkMark === null || linkMark === void 0 ? void 0 : linkMark.attrs.href, "\"")); } } var fileName; if (node.attrs.type === 'external') { fileName = node.attrs.url; } else { var _context$conversion$m, _context$conversion; fileName = (_context$conversion$m = context === null || context === void 0 || (_context$conversion = context.conversion) === null || _context$conversion === void 0 || (_context$conversion = _context$conversion.mediaConversion) === null || _context$conversion === void 0 || (_context$conversion = _context$conversion[node.attrs.id]) === null || _context$conversion === void 0 ? void 0 : _context$conversion.transform) !== null && _context$conversion$m !== void 0 ? _context$conversion$m : node.attrs.id; } if ((context === null || context === void 0 || (_context$conversion2 = context.conversion) === null || _context$conversion2 === void 0 || (_context$conversion2 = _context$conversion2.mediaConversion) === null || _context$conversion2 === void 0 || (_context$conversion2 = _context$conversion2[node.attrs.id]) === null || _context$conversion2 === void 0 ? void 0 : _context$conversion2.embed) === false) { return "[^".concat(fileName, "]"); } if (wikiAttrs.length) { return "!".concat(fileName, "|").concat(wikiAttrs.join(','), "!"); } // default to thumbnail if no width or height is set return "!".concat(fileName, "|thumbnail!"); };