UNPKG

@atlaskit/editor-wikimarkup-transformer

Version:

Wiki markup transformer for JIRA and Confluence

44 lines (43 loc) 2.26 kB
export const media = (node, { context, parent } = {}) => { var _context$conversion2, _context$conversion2$, _context$conversion2$2; const wikiAttrs = []; // Parent width takes precedence over internal dimension attributes if (parent && parent.attrs.width) { // Parent width is defined in percents wikiAttrs.push(`width=${parent.attrs.width}%`); } else { if (node.attrs.width) { wikiAttrs.push(`width=${node.attrs.width}`); } if (node.attrs.height) { wikiAttrs.push(`height=${node.attrs.height}`); } } if (node.attrs.alt) { wikiAttrs.push(`alt="${node.attrs.alt}"`); } if (node.marks.length) { const linkMark = node.marks.find(mark => mark.type.name === 'link'); if (linkMark) { wikiAttrs.push(`href="${linkMark === null || linkMark === void 0 ? void 0 : linkMark.attrs.href}"`); } } let fileName; if (node.attrs.type === 'external') { fileName = node.attrs.url; } else { var _context$conversion$m, _context$conversion, _context$conversion$m2, _context$conversion$m3; fileName = (_context$conversion$m = context === null || context === void 0 ? void 0 : (_context$conversion = context.conversion) === null || _context$conversion === void 0 ? void 0 : (_context$conversion$m2 = _context$conversion.mediaConversion) === null || _context$conversion$m2 === void 0 ? void 0 : (_context$conversion$m3 = _context$conversion$m2[node.attrs.id]) === null || _context$conversion$m3 === void 0 ? void 0 : _context$conversion$m3.transform) !== null && _context$conversion$m !== void 0 ? _context$conversion$m : node.attrs.id; } if ((context === null || context === void 0 ? void 0 : (_context$conversion2 = context.conversion) === null || _context$conversion2 === void 0 ? void 0 : (_context$conversion2$ = _context$conversion2.mediaConversion) === null || _context$conversion2$ === void 0 ? void 0 : (_context$conversion2$2 = _context$conversion2$[node.attrs.id]) === null || _context$conversion2$2 === void 0 ? void 0 : _context$conversion2$2.embed) === false) { return `[^${fileName}]`; } if (wikiAttrs.length) { return `!${fileName}|${wikiAttrs.join(',')}!`; } // default to thumbnail if no width or height is set return `!${fileName}|thumbnail!`; };