mirror of
https://github.com/docsifyjs/docsify.git
synced 2025-12-08 19:55:52 +00:00
* chore: added new linter config * chore: linting fixes * chore: refactore in linting config and minor linting fixes
45 lines
1.1 KiB
JavaScript
45 lines
1.1 KiB
JavaScript
import { getAndRemoveConfig } from '../compiler';
|
|
import { isAbsolutePath, getPath, getParentPath } from '../../router/util';
|
|
|
|
export const imageCompiler = ({ renderer, contentBase, router }) =>
|
|
(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}" height="${width}"`);
|
|
}
|
|
}
|
|
|
|
if (config.class) {
|
|
attrs.push(`class="${config.class}"`);
|
|
}
|
|
|
|
if (config.id) {
|
|
attrs.push(`id="${config.id}"`);
|
|
}
|
|
|
|
if (!isAbsolutePath(href)) {
|
|
url = getPath(contentBase, getParentPath(router.getCurrentPath()), href);
|
|
}
|
|
|
|
return `<img src="${url}" data-origin="${href}" alt="${text}" ${attrs.join(
|
|
' '
|
|
)} />`;
|
|
});
|