import m from 'mithril'
import { XmlEntities } from 'html-entities'
import twemoji from 'twemoji'
import render from 'mithril-node-render'
import fetch from './fetch'
import { youtubeKey } from './constants'
import { replaceAsync } from './utils'
const entities = new XmlEntities()
export async function cleanMarkup (html) {
if (!html) {
return Promise.resolve('')
}
html = twemoji.parse(html, {ext: '.svg', folder: 'svg'})
// replace HTML entities with decimal entities
html = html.replace(/\xA0/g, ' ')
html = html.replace(/ /g, ' ')
html = html.replace(/ /g, ' ')
// fix some tags
html = html.replace(//g, '')
html = html.replace(/<\/u>/g, '')
html = html.replace(//g, '')
html = html.replace(/<\/s>/g, '')
html = html.replace(/
\s*/g, '
') html = html.replace(/\s*<\/p>/g, '
') // html = fixParagraphIndent(html) html = fixDoubleSpacing(html) // fix floating blockquote tags html = html.replace('', '') html = html.replace('', '') /* let imageEmbed = //g html = await replaceAsync(html, imageEmbed, (match, originalUrl, cdnUrl) => { return render(m('img', {src: entities.decode(cdnUrl), alt: 'Image'}), {strict: true}) }) */ // 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 = 'https://fimfiction.net' + entities.decode(url) } else { // do something else } } return head + url + tail }) let cache = new Map() let completeCount = 0 let matchYouTube = /