Fix for arabic etc, remove DELETE control character, add alt attributes, less sections

This commit is contained in:
daniel-j 2018-05-08 21:11:50 +02:00
parent 7a01902056
commit 1a2402445b
3 changed files with 23 additions and 23 deletions

View file

@ -400,7 +400,7 @@ class FimFic2Epub extends EventEmitter {
} }
chain = chain.then(template.createChapter.bind(null, this, { chain = chain.then(template.createChapter.bind(null, this, {
title: this.options.addChapterHeadings ? ch.title : null, title: ch.title,
link: this.options.addCommentsLink ? ch.link : null, link: this.options.addCommentsLink ? ch.link : null,
linkNotes: this.options.includeAuthorNotes && this.options.useAuthorNotesIndex && chapter.notes ? 'note_' + zeroFill(3, i + 1) + '.xhtml' : null, linkNotes: this.options.includeAuthorNotes && this.options.useAuthorNotesIndex && chapter.notes ? 'note_' + zeroFill(3, i + 1) + '.xhtml' : null,
content: content, content: content,

View file

@ -15,12 +15,15 @@ export async function cleanMarkup (html) {
return Promise.resolve('') return Promise.resolve('')
} }
html = html.normalize('NFC') // normalize unicode
html = twemoji.parse(html, {ext: '.svg', folder: 'svg'}) html = twemoji.parse(html, {ext: '.svg', folder: 'svg'})
// replace HTML entities with decimal entities // replace HTML entities with decimal entities
html = html.replace(/\xA0/ig, ' ') html = html.replace(/\xA0/g, ' ')
html = html.replace(/ /ig, ' ') html = html.replace(/ /ig, ' ')
html = html.replace(/ /ig, ' ') html = html.replace(/ /ig, ' ')
html = html.replace(/\u007F/g, '') // remove invalid token
// fix some tags // fix some tags
html = html.replace(/<u>/ig, '<span style="text-decoration: underline">') html = html.replace(/<u>/ig, '<span style="text-decoration: underline">')
@ -40,12 +43,9 @@ export async 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">')
/* // add alt attributes to images that don't have them
let imageEmbed = /<img data-src="(.*?)" class="user_image" src="(.*?)" data-lightbox\/>/g let imageEmbed = /<img src="(.*?)" \/>/g
html = await replaceAsync(html, imageEmbed, (match, originalUrl, cdnUrl) => { html = await replaceAsync(html, imageEmbed, (match, src) => render(m('img', {src: entities.decode(src), alt: 'Image'}), {strict: true}))
return render(m('img', {src: entities.decode(cdnUrl), alt: 'Image'}), {strict: true})
})
*/
// 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>

View file

@ -84,14 +84,14 @@ export function createChapter (ffc, ch, isNotesChapter) {
return Promise.all([ return Promise.all([
render( render(
m('html', {xmlns: NS.XHTML, 'xmlns:epub': NS.OPS}, [ m('html', {xmlns: NS.XHTML, 'xmlns:epub': NS.OPS, lang: 'en'}, [
m('head', [ m('head', [
m('meta', {charset: 'utf-8'}), m('meta', {charset: 'utf-8'}),
m('link', {rel: 'stylesheet', type: 'text/css', href: '../Styles/style.css'}), m('link', {rel: 'stylesheet', type: 'text/css', href: '../Styles/style.css'}),
m('title', title) m('title', title)
]), ]),
m('body', {'epub:type': 'bodymatter chapter'}, m('section', [ m('body', {'epub:type': 'bodymatter chapter'}, m('div', [
title ? m('.chapter-title', [ ffc.options.addChapterHeadings || !linkNotes ? m('.chapter-title', [
!isNotesChapter ? m('aside.info', !isNotesChapter ? m('aside.info',
m('span.label', ffc.options.wordsPerMinute ? calcReadingTime(ffc, ffc.storyInfo.chapters[index].realWordCount) : ''), m('span.label', ffc.options.wordsPerMinute ? calcReadingTime(ffc, ffc.storyInfo.chapters[index].realWordCount) : ''),
m('span.label', ffc.storyInfo.chapters[index].realWordCount.toLocaleString('en-GB') + ' words') m('span.label', ffc.storyInfo.chapters[index].realWordCount.toLocaleString('en-GB') + ' words')
@ -309,14 +309,14 @@ export function createNav (ffc) {
} }
return render( return render(
m('html', {xmlns: NS.XHTML, 'xmlns:epub': NS.OPS}, [ m('html', {xmlns: NS.XHTML, 'xmlns:epub': NS.OPS, lang: 'en'}, [
m('head', [ m('head', [
m('meta', {charset: 'utf-8'}), m('meta', {charset: 'utf-8'}),
m('link', {rel: 'stylesheet', type: 'text/css', href: 'Styles/style.css'}), m('link', {rel: 'stylesheet', type: 'text/css', href: 'Styles/style.css'}),
m('link', {rel: 'stylesheet', type: 'text/css', href: 'Styles/navstyle.css'}), m('link', {rel: 'stylesheet', type: 'text/css', href: 'Styles/navstyle.css'}),
m('title', 'Contents') m('title', 'Contents')
]), ]),
m('body', {'epub:type': 'frontmatter toc'}, m('section', [ m('body', {'epub:type': 'frontmatter toc'}, m('div', [
m('nav.invisible', {'epub:type': 'toc'}, m('ol', list)), m('nav.invisible', {'epub:type': 'toc'}, m('ol', list)),
m('h3', 'Contents'), m('h3', 'Contents'),
m('ul#toc.hidden', prettyList), m('ul#toc.hidden', prettyList),
@ -336,14 +336,14 @@ export function createNotesNav (ffc) {
}) })
return render( return render(
m('html', {xmlns: NS.XHTML, 'xmlns:epub': NS.OPS}, [ m('html', {xmlns: NS.XHTML, 'xmlns:epub': NS.OPS, lang: 'en'}, [
m('head', [ m('head', [
m('meta', {charset: 'utf-8'}), m('meta', {charset: 'utf-8'}),
m('link', {rel: 'stylesheet', type: 'text/css', href: 'Styles/style.css'}), m('link', {rel: 'stylesheet', type: 'text/css', href: 'Styles/style.css'}),
m('link', {rel: 'stylesheet', type: 'text/css', href: 'Styles/navstyle.css'}), m('link', {rel: 'stylesheet', type: 'text/css', href: 'Styles/navstyle.css'}),
m('title', 'Author\'s Notes') m('title', 'Author\'s Notes')
]), ]),
m('body#navpage', {'epub:type': 'frontmatter toc'}, m('section', [ m('body#navpage', {'epub:type': 'frontmatter toc'}, m('div', [
m('h3', 'Author\'s Notes'), m('h3', 'Author\'s Notes'),
m('#toc', list) m('#toc', list)
])) ]))
@ -371,7 +371,7 @@ export function createCoverPage (ffc) {
} }
return render( return render(
m('html', {xmlns: NS.XHTML, 'xmlns:epub': NS.OPS}, [ m('html', {xmlns: NS.XHTML, 'xmlns:epub': NS.OPS, lang: 'en'}, [
m('head', [ m('head', [
ffc.coverImage ? m('meta', {name: 'viewport', content: 'width=' + width + ', height=' + height}) : null, ffc.coverImage ? m('meta', {name: 'viewport', content: 'width=' + width + ', height=' + height}) : null,
m('title', 'Cover'), m('title', 'Cover'),
@ -425,21 +425,21 @@ export function createTitlePage (ffc) {
} }
return render( return render(
m('html', {xmlns: NS.XHTML, 'xmlns:epub': NS.OPS}, [ m('html', {xmlns: NS.XHTML, 'xmlns:epub': NS.OPS, lang: 'en'}, [
m('head', [ m('head', [
m('meta', {charset: 'utf-8'}), m('meta', {charset: 'utf-8'}),
m('link', {rel: 'stylesheet', type: 'text/css', href: '../Styles/style.css'}), m('link', {rel: 'stylesheet', type: 'text/css', href: '../Styles/style.css'}),
m('link', {rel: 'stylesheet', type: 'text/css', href: '../Styles/titlestyle.css'}), m('link', {rel: 'stylesheet', type: 'text/css', href: '../Styles/titlestyle.css'}),
m('title', ffc.storyInfo.title) m('title', ffc.storyInfo.title)
]), ]),
m('body#titlepage', {'epub:type': 'frontmatter titlepage'}, m('section', [ m('body#titlepage', {'epub:type': 'frontmatter titlepage'}, m('div', [
m('header.title', [ m('header.title', [
m('div', {className: 'content-rating content-rating-' + ffc.storyInfo.content_rating_text.toLowerCase()}, ffc.storyInfo.content_rating_text.charAt(0).toUpperCase()), m('div', {className: 'content-rating content-rating-' + ffc.storyInfo.content_rating_text.toLowerCase()}, ffc.storyInfo.content_rating_text.charAt(0).toUpperCase()),
m('section.story_name', ffc.storyInfo.title + ' '), m('.story_name', ffc.storyInfo.title + ' '),
m('section.author', ['by ', m('b', ffc.storyInfo.author.name)]) m('.author', ['by ', m('b', ffc.storyInfo.author.name)])
]), ]),
// m('hr'), // m('hr'),
m('section.tags', ffc.tags.filter((tag) => tag.type !== 'character').map((tag) => m('.tags', ffc.tags.filter((tag) => tag.type !== 'character').map((tag) =>
[m('span.tagbox', m('span', {className: tag.className}, tag.name))] [m('span.tagbox', m('span', {className: tag.className}, tag.name))]
)), )),
m('.readlink', m('a', {href: ffc.storyInfo.url}, 'Story on Fimfiction')), m('.readlink', m('a', {href: ffc.storyInfo.url}, 'Story on Fimfiction')),
@ -451,7 +451,7 @@ export function createTitlePage (ffc) {
]), m('hr.old')] : null, ]), m('hr.old')] : null,
m('#description', tokenContent), m('#description', tokenContent),
m('.bottom', [ m('.bottom', [
m('section', {className: 'completed-status completed-status-' + ffc.storyInfo.status.toLowerCase()}, [ m('div', {className: 'completed-status completed-status-' + ffc.storyInfo.status.toLowerCase()}, [
m('i.fa.fa-fw.fa-' + completedIcon[ffc.storyInfo.status.toLowerCase()], ' '), m('i.fa.fa-fw.fa-' + completedIcon[ffc.storyInfo.status.toLowerCase()], ' '),
ffc.storyInfo.status ffc.storyInfo.status
]), ]),
@ -462,7 +462,7 @@ export function createTitlePage (ffc) {
ffc.options.calculateReadingEase && ffc.readingEase ? infoBox('Reading Ease', (Math.round(ffc.readingEase.ease * 100) / 100).toLocaleString('en-GB')) : null ffc.options.calculateReadingEase && ffc.readingEase ? infoBox('Reading Ease', (Math.round(ffc.readingEase.ease * 100) / 100).toLocaleString('en-GB')) : null
]), ]),
// m('hr'), // m('hr'),
m('section.tags', ffc.tags.filter((tag) => tag.type === 'character').map((tag) => m('.tags', ffc.tags.filter((tag) => tag.type === 'character').map((tag) =>
[m('span.tagbox', m('span', {className: tag.className}, tag.name))] [m('span.tagbox', m('span', {className: tag.className}, tag.name))]
)) ))
])) ]))