2019-07-16 20:05:47 +02:00
|
|
|
const htmlUtils = require('lib/htmlUtils');
|
|
|
|
const utils = require('./utils');
|
2019-10-07 23:14:49 +02:00
|
|
|
const noteStyle = require('./noteStyle');
|
2019-07-16 20:05:47 +02:00
|
|
|
|
|
|
|
class HtmlToHtml {
|
|
|
|
constructor(options) {
|
|
|
|
this.resourceBaseUrl_ = 'resourceBaseUrl' in options ? options.resourceBaseUrl : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
render(markup, theme, options) {
|
2019-07-21 01:18:51 +02:00
|
|
|
const html = htmlUtils.processImageTags(markup, data => {
|
|
|
|
if (!data.src) return null;
|
|
|
|
|
|
|
|
const r = utils.imageReplacement(data.src, options.resources, this.resourceBaseUrl_);
|
|
|
|
if (!r) return null;
|
2019-07-16 20:05:47 +02:00
|
|
|
|
|
|
|
if (typeof r === 'string') {
|
2019-07-21 01:18:51 +02:00
|
|
|
return {
|
|
|
|
type: 'replaceElement',
|
|
|
|
html: r,
|
|
|
|
};
|
2019-07-16 20:05:47 +02:00
|
|
|
} else {
|
2019-07-21 01:18:51 +02:00
|
|
|
return {
|
|
|
|
type: 'setAttributes',
|
|
|
|
attrs: r,
|
|
|
|
};
|
2019-07-16 20:05:47 +02:00
|
|
|
}
|
2019-07-21 01:18:51 +02:00
|
|
|
});
|
2019-07-16 20:05:47 +02:00
|
|
|
|
2019-10-07 23:14:49 +02:00
|
|
|
const cssStrings = noteStyle(theme, options);
|
|
|
|
const styleHtml = `<style>${cssStrings.join('\n')}</style>`;
|
|
|
|
|
2019-07-16 20:05:47 +02:00
|
|
|
return {
|
2019-10-07 23:14:49 +02:00
|
|
|
html: styleHtml + html,
|
2019-07-16 20:05:47 +02:00
|
|
|
cssFiles: [],
|
2019-07-29 15:43:53 +02:00
|
|
|
};
|
2019-07-16 20:05:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-29 15:43:53 +02:00
|
|
|
module.exports = HtmlToHtml;
|