-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarkdown.js
22 lines (18 loc) · 848 Bytes
/
markdown.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const getImagePath = require('./code/utils/get-image-path')
const sizeOf = require("image-size");
const path = require('path')
module.exports = exports = function renderer({ Marked, _relativeURL }) {
Marked.image = (href, title, text) => {
const { width, height } = sizeOf(path.join(__dirname, href));
return `<div class="lazyload" style="padding-bottom: ${(height / width) *
100}%" data-bg="url(${getImagePath(href)})" title="${text}"><a data-no-swup target="_blank" class="download-link" title="Open full image" href="${href}"></a></div>`;
};
Marked.link = (href, title, text) => {
const target = href.match(/^https?:/i)
? 'target="_blank" rel="noopener noreferrer"'
: "";
title = title ? `title="${title}"` : "";
return `<a href="${href}" ${target} ${title}>${text}</a>`;
};
return Marked;
};