-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Expand file tree
/
Copy pathimage.js
More file actions
61 lines (51 loc) · 1.37 KB
/
image.js
File metadata and controls
61 lines (51 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { getAndRemoveConfig } from '../utils';
import {
isAbsolutePath,
isPathRootRelative,
getPath,
getParentPath,
} from '../../router/util';
export const imageCompiler = ({
renderer,
contentBase,
router,
rootRelativeImageURL,
}) =>
(renderer.image = (href, title, text) => {
let url = href;
let attrs = [];
const { str, config } = getAndRemoveConfig(title);
title = str;
if (config['no-zoom']) {
attrs.push('data-no-zoom');
}
if (title) {
attrs.push(`title="${title}"`);
}
if (config.size) {
const [width, height] = config.size.split('x');
if (height) {
attrs.push(`width="${width}" height="${height}"`);
} else {
attrs.push(`width="${width}"`);
}
}
if (config.class) {
attrs.push(`class="${config.class}"`);
}
if (config.id) {
attrs.push(`id="${config.id}"`);
}
if (!isAbsolutePath(href)) {
url =
isPathRootRelative(href) && rootRelativeImageURL !== false
? getPath('/' + String(rootRelativeImageURL), href)
: getPath(contentBase, getParentPath(router.getCurrentPath()), href);
}
if (attrs.length > 0) {
return `<img src="${url}" data-origin="${href}" alt="${text}" ${attrs.join(
' '
)} />`;
}
return `<img src="${url}" data-origin="${href}" alt="${text}"${attrs}>`;
});