From 4092c6d350e884cf10aeb6375baf9998c6f28ae2 Mon Sep 17 00:00:00 2001 From: daniel-j Date: Wed, 7 Jun 2017 11:13:31 +0200 Subject: [PATCH] Fix image embeds --- src/cleanMarkup.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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 = /
/g html = html.replace(matchSoundCloud, (match, url) => { return render(m('.soundcloud.leftalign', [ - 'SoundCloud song ', m('a', {href: url, rel: 'nofollow'}, url.replace('https://soundcloud.com', '')) + 'SoundCloud song ', m('a', {href: entities.decode(url), rel: 'nofollow'}, url.replace('https://soundcloud.com', '')) ])) }) @@ -73,7 +81,7 @@ export function cleanMarkup (html) { html = html.replace(matchStoryEmbed, (match, id, storyLink, storyTitle, author) => { return render(m('.story', [ 'Story: ', - m('a', {href: 'http://fimfiction.net' + storyLink, rel: 'nofollow'}, storyTitle), + m('a', {href: 'http://fimfiction.net' + entities.decode(storyLink), rel: 'nofollow'}, storyTitle), ' by ' + author ])) })