diff --git a/src/cleanMarkup.js b/src/cleanMarkup.js index baf284f..cd81c38 100644 --- a/src/cleanMarkup.js +++ b/src/cleanMarkup.js @@ -1,10 +1,13 @@ import m from 'mithril' +import { XmlEntities } from 'html-entities' import render from './lib/mithril-node-render' import fetch from './fetch' import { youtubeKey } from './constants' +const entities = new XmlEntities() + export function cleanMarkup (html) { if (!html) { return Promise.resolve('') @@ -35,13 +38,18 @@ export function cleanMarkup (html) { html = html.replace('
', '') html = html.replace('', '') + let imageEmbed = //g + html = html.replace(imageEmbed, (match, originalUrl, cdnUrl) => { + return render(m('img', {src: entities.decode(cdnUrl), alt: 'Image'})) + }) + // Fix links pointing to pages on fimfiction // Example: djazz let matchLink = /()/g html = html.replace(matchLink, (match, head, url, tail) => { if (url.substring(0, 1) !== '#' && url.substring(0, 2) !== '//' && url.substring(0, 4) !== 'http') { if (url.substring(0, 1) === '/') { - url = 'http://www.fimfiction.net' + url + url = 'http://www.fimfiction.net' + entities.decode(url) } else { // do something else } @@ -64,7 +72,7 @@ export function cleanMarkup (html) { let matchSoundCloud = /