Replace Cloudflare links in exported HTML

Emoji images are now converted to data URLs

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2021-08-05 21:32:24 +02:00
parent 515fed3db0
commit 4526542944
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3

View file

@ -620,6 +620,18 @@ export function removeDOMEvents (view) {
}
window.removeDOMEvents = removeDOMEvents
function toDataURL (url, callback) {
fetch(url).then(response => {
const fr = new FileReader()
fr.onload = function () {
callback(this.result)
}
response.blob().then(blob => {
fr.readAsDataURL(blob)
})
})
}
function generateCleanHTML (view) {
const src = view.clone()
const eles = src.find('*')
@ -634,10 +646,9 @@ function generateCleanHTML (view) {
src.find('input.task-list-item-checkbox').attr('disabled', '')
// replace emoji image path
src.find('img.emoji').each((key, value) => {
let name = $(value).attr('alt')
name = name.substr(1)
name = name.slice(0, name.length - 1)
$(value).attr('src', `https://cdnjs.cloudflare.com/ajax/libs/emojify.js/1.1.0/images/basic/${name}.png`)
toDataURL($(value).attr('src'), dataURL => {
$(value).attr('src', dataURL)
})
})
// replace video to iframe
src.find('div[data-videoid]').each((key, value) => {