({ renderer, contentBase, router })
| 2 | import { isAbsolutePath, getPath, getParentPath } from '../../router/util'; |
| 3 | |
| 4 | export const imageCompiler = ({ renderer, contentBase, router }) => |
| 5 | (renderer.image = (href, title, text) => { |
| 6 | let url = href; |
| 7 | let attrs = []; |
| 8 | |
| 9 | const { str, config } = getAndRemoveConfig(title); |
| 10 | title = str; |
| 11 | |
| 12 | if (config['no-zoom']) { |
| 13 | attrs.push('data-no-zoom'); |
| 14 | } |
| 15 | |
| 16 | if (title) { |
| 17 | attrs.push(`title="${title}"`); |
| 18 | } |
| 19 | |
| 20 | if (config.size) { |
| 21 | const [width, height] = config.size.split('x'); |
| 22 | if (height) { |
| 23 | attrs.push(`width="${width}" height="${height}"`); |
| 24 | } else { |
| 25 | attrs.push(`width="${width}"`); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | if (config.class) { |
| 30 | attrs.push(`class="${config.class}"`); |
| 31 | } |
| 32 | |
| 33 | if (config.id) { |
| 34 | attrs.push(`id="${config.id}"`); |
| 35 | } |
| 36 | |
| 37 | if (!isAbsolutePath(href)) { |
| 38 | url = getPath(contentBase, getParentPath(router.getCurrentPath()), href); |
| 39 | } |
| 40 | |
| 41 | if (attrs.length > 0) { |
| 42 | return `<img src="${url}" data-origin="${href}" alt="${text}" ${attrs.join( |
| 43 | ' ' |
| 44 | )} />`; |
| 45 | } |
| 46 | |
| 47 | return `<img src="${url}" data-origin="${href}" alt="${text}"${attrs}>`; |
| 48 | }); |
no test coverage detected
searching dependent graphs…