mirror of
https://github.com/daniel-j/fimfic2epub.git
synced 2024-09-30 00:56:13 +13:00
Fix image embeds
This commit is contained in:
parent
24fbb09508
commit
4092c6d350
1 changed files with 11 additions and 3 deletions
|
@ -1,10 +1,13 @@
|
||||||
|
|
||||||
import m from 'mithril'
|
import m from 'mithril'
|
||||||
|
import { XmlEntities } from 'html-entities'
|
||||||
import render from './lib/mithril-node-render'
|
import render from './lib/mithril-node-render'
|
||||||
|
|
||||||
import fetch from './fetch'
|
import fetch from './fetch'
|
||||||
import { youtubeKey } from './constants'
|
import { youtubeKey } from './constants'
|
||||||
|
|
||||||
|
const entities = new XmlEntities()
|
||||||
|
|
||||||
export function cleanMarkup (html) {
|
export function cleanMarkup (html) {
|
||||||
if (!html) {
|
if (!html) {
|
||||||
return Promise.resolve('')
|
return Promise.resolve('')
|
||||||
|
@ -35,13 +38,18 @@ export function cleanMarkup (html) {
|
||||||
html = html.replace('<blockquote style="margin: 10px 0px; box-sizing:border-box; -moz-box-sizing:border-box;margin-right:25px; padding: 15px;background-color: #F7F7F7;border: 1px solid #AAA;width: 50%;float:left;box-shadow: 5px 5px 0px #EEE;">', '<blockquote class="left_insert">')
|
html = html.replace('<blockquote style="margin: 10px 0px; box-sizing:border-box; -moz-box-sizing:border-box;margin-right:25px; padding: 15px;background-color: #F7F7F7;border: 1px solid #AAA;width: 50%;float:left;box-shadow: 5px 5px 0px #EEE;">', '<blockquote class="left_insert">')
|
||||||
html = html.replace('<blockquote style="margin: 10px 0px; box-sizing:border-box; -moz-box-sizing:border-box;margin-left:25px; padding: 15px;background-color: #F7F7F7;border: 1px solid #AAA;width: 50%;float:right;box-shadow: 5px 5px 0px #EEE;">', '<blockquote class="right_insert">')
|
html = html.replace('<blockquote style="margin: 10px 0px; box-sizing:border-box; -moz-box-sizing:border-box;margin-left:25px; padding: 15px;background-color: #F7F7F7;border: 1px solid #AAA;width: 50%;float:right;box-shadow: 5px 5px 0px #EEE;">', '<blockquote class="right_insert">')
|
||||||
|
|
||||||
|
let imageEmbed = /<img data-src="(.*?)" class="user_image" src="(.*?)" data-lightbox\/>/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
|
// Fix links pointing to pages on fimfiction
|
||||||
// Example: <a href="/user/djazz" rel="nofollow">djazz</a>
|
// Example: <a href="/user/djazz" rel="nofollow">djazz</a>
|
||||||
let matchLink = /(<a .?href=")(.+?)(".+?>)/g
|
let matchLink = /(<a .?href=")(.+?)(".+?>)/g
|
||||||
html = html.replace(matchLink, (match, head, url, tail) => {
|
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.substring(0, 2) !== '//' && url.substring(0, 4) !== 'http') {
|
||||||
if (url.substring(0, 1) === '/') {
|
if (url.substring(0, 1) === '/') {
|
||||||
url = 'http://www.fimfiction.net' + url
|
url = 'http://www.fimfiction.net' + entities.decode(url)
|
||||||
} else {
|
} else {
|
||||||
// do something else
|
// do something else
|
||||||
}
|
}
|
||||||
|
@ -64,7 +72,7 @@ export function cleanMarkup (html) {
|
||||||
let matchSoundCloud = /<div data-controller="oembed" class="oembed" data-url="(.*?)" .+?<\/div>/g
|
let matchSoundCloud = /<div data-controller="oembed" class="oembed" data-url="(.*?)" .+?<\/div>/g
|
||||||
html = html.replace(matchSoundCloud, (match, url) => {
|
html = html.replace(matchSoundCloud, (match, url) => {
|
||||||
return render(m('.soundcloud.leftalign', [
|
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) => {
|
html = html.replace(matchStoryEmbed, (match, id, storyLink, storyTitle, author) => {
|
||||||
return render(m('.story', [
|
return render(m('.story', [
|
||||||
'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
|
' by ' + author
|
||||||
]))
|
]))
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue