|
|
|
@ -1,7 +1,10 @@
|
|
|
|
|
const { marked } = require('marked')
|
|
|
|
|
|
|
|
|
|
const configStore = require('./../config.js')
|
|
|
|
|
const Media = require('./../factories/media.js')
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
@ -38,6 +41,13 @@ function cleanUrl(sanitize, base, href) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const renderer = {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param {string} href
|
|
|
|
|
* @param {string} title
|
|
|
|
|
* @param {string} text
|
|
|
|
|
*/
|
|
|
|
|
link(href, title, text) {
|
|
|
|
|
|
|
|
|
|
href = cleanUrl(this.options.sanitize, this.options.baseUrl, href)
|
|
|
|
@ -59,6 +69,42 @@ const renderer = {
|
|
|
|
|
|
|
|
|
|
out += '>' + text + '</a>'
|
|
|
|
|
|
|
|
|
|
return out
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param {string} href
|
|
|
|
|
* @param {string} title
|
|
|
|
|
* @param {string} text
|
|
|
|
|
*/
|
|
|
|
|
image(href, title, text) {
|
|
|
|
|
|
|
|
|
|
href = cleanUrl(this.options.sanitize, this.options.baseUrl, href)
|
|
|
|
|
|
|
|
|
|
if (href === null) {
|
|
|
|
|
return text
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// check if href for image is relative
|
|
|
|
|
if (!href.match(/^(http|https):\/\//)) {
|
|
|
|
|
const markedDirPath = configStore.get('markedDirPath')
|
|
|
|
|
|
|
|
|
|
// check if dirPath are exists from options
|
|
|
|
|
if (markedDirPath || markedDirPath === '') {
|
|
|
|
|
const media = new Media(markedDirPath)
|
|
|
|
|
href = media.resolve(href)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let out = `<img src="${href}" alt="${text}"`
|
|
|
|
|
|
|
|
|
|
if (title) {
|
|
|
|
|
out += ` title="${title}"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out += this.options.xhtml ? '/>' : '>'
|
|
|
|
|
|
|
|
|
|
return out
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|