MCPcopy
hub / github.com/docsifyjs/docsify / imageCompiler

Function imageCompiler

src/core/render/compiler/image.js:4–48  ·  view source on GitHub ↗
({ renderer, contentBase, router })

Source from the content-addressed store, hash-verified

2import { isAbsolutePath, getPath, getParentPath } from '../../router/util';
3
4export 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 });

Callers 1

_initRendererMethod · 0.90

Calls 3

getAndRemoveConfigFunction · 0.90
getPathFunction · 0.90
getCurrentPathMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…