diff --git a/extension/manifest.json b/extension/manifest.json index 16cbf2f..15b3424 100644 --- a/extension/manifest.json +++ b/extension/manifest.json @@ -4,7 +4,7 @@ "name": "fimfic2epub", "short_name": "fimfic2epub", "description": "Improved EPUB exporter for Fimfiction", - "version": "1.4.9", + "version": "1.5.0", "icons": { "128": "icon-128.png" diff --git a/package.json b/package.json index f93b2ab..e2787cd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fimfic2epub", - "version": "1.4.9", + "version": "1.5.0", "description": "Tool to generate improved EPUB ebooks from Fimfiction stories", "author": "djazz", "repository": { diff --git a/src/cleanMarkup.js b/src/cleanMarkup.js index 032d3e9..43e5cd3 100644 --- a/src/cleanMarkup.js +++ b/src/cleanMarkup.js @@ -20,13 +20,8 @@ export function cleanMarkup (html) { } return new Promise((resolve, reject) => { - // replace HTML non-breaking spaces with normal spaces - html = html.replace(/ /g, ' ') - html = fixParagraphIndent(html) - html = fixDoubleSpacing(html) - // fix center tags html = html.replace(/
/g, '

') html = html.replace(/<\/center>/g, '

') @@ -108,6 +103,12 @@ export function cleanMarkup (html) { function continueParsing () { html = tidy(html, tidyOptions).trim() + // replace HTML non-breaking spaces with normal spaces + html = html.replace(/ /g, ' ') + html = html.replace(/ /g, ' ') + + html = fixDoubleSpacing(html) + resolve(html) } }) diff --git a/src/constants.js b/src/constants.js index b502688..8529626 100644 --- a/src/constants.js +++ b/src/constants.js @@ -16,7 +16,6 @@ export const tidyOptions = { 'alt-text': 'Image', 'wrap': '0', 'quiet': 'yes', - 'show-warnings': 0, 'newline': 'LF', 'tidy-mark': 'no', 'show-body-only': 'auto' diff --git a/src/same.xhtml b/src/same.xhtml new file mode 100644 index 0000000..99d86bd --- /dev/null +++ b/src/same.xhtml @@ -0,0 +1,125 @@ +

This chapter is designed to test the capabilities of various ePub extraction tools against each BBCode tag supported by FIMFiction.net. First of all, note that this paragraph begins with a tab indent—many tools will remove this. Next, here is the set of non-ANSI characters that I frequently use in my stories: “” ‘’ — … (smart double quotes, smart single quotes, em-dash, and ellipses).

+

Next are the tags that should work in-line: [b] + bold[/b], [i] + italics[/i], [u] + underline[/u], [s] + strikethrough[/s], [smcaps] + small caps[/smcaps], [spoiler] + spoiler text[/spoiler], [url] + hyperlink[/url], [email] + user@server.com[/email], and finally an in-line image: [img] + Image[/img]. +

+

+ There's a known bug in translating FIMFiction stories where consecutive italicized paragraphs lose the italics after the first paragraph. Well, this paragraph is supposed to be italicized. +

+

+ And so is this one. +

+

+ And ending with this one. +

+

Let’s quickly step through all of the named color tags: + red, + silver, + orange, + yellow, + brown, + green, + olive, + cornflowerblue, + cyan, + purple, + pink, + hotpink, + lime, + white (white), + lightgrey, + indigo, + darkblue, + lightblue, + blue, + gold, + navy, + chartreuse, and + teal. Here are some of the colors I use to code character's thoughts in my “Thought Experiments” series: + #0077D0 for Vinyl Scratch, + #60BB50 for Spike, + purple for Twilight Sparkle, + hotpink for Pinkie Pie, and + darkblue for Rainbow Dash. +

+

Size can be indicated by either an absolute number, or in "ems", which is a percentage scaling:

+

[size=24] + Size 24, which should be normal-size text for default settings[/size] +

+

[size=12] + Size 12, which should be half-size text for default settings[/size] +

+

[size=48] + Size 48, which should be double-size text for default settings[/size] +

+

[size=1em] + 1 em text[/size] +

+

[size=.5em] + 0.5 em text[/size] +

+

[size=2em] + 2 em text[/size] +

+

+
+

Just above this paragraph should be a horizontal rule, or [hr] tag.

+

+

[center]Centered text[/center]

+

+
+[right]Right-aligned text[/right] +
+

+
+[quote] This is a quote. + + +

One big problem I've found with ePub extractors is handling multiple-paragraph quotes. This paragraph should still be inside the above quote tag.

+

+

[center]Centered in the quote.[/center]

+

[/quote]

+
+

+
+

Here's an image all by itself:

+

+ Image +

+

Here's a YouTube video:

+

+
+ + d.notive - Vicious Lies (Depeche Mode Imitation) + +
+ d.notive - Vicious Lies (Depeche Mode Imitation) on YouTube +
+
+

+
+

+
+[left_insert]This creates left-aligned text that wraps at the center of the screen. Here's some + lorum ipsum to demonstrate line-wrapping: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. + + +

Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.[/left_insert]

+
+

+
+[right_insert]This creates left-aligned text starting at the center of the screen. Here's some + lorum ipsum to demonstrate line-wrapping: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. + + +

Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.[/right_insert]

+
+

+
diff --git a/src/templates.js b/src/templates.js index 1dc23b8..6facd82 100644 --- a/src/templates.js +++ b/src/templates.js @@ -50,15 +50,17 @@ export function createChapter (ch) { m('h1', title), m('hr') ]) : null, - sections, - m('p.double', {style: 'text-align: center; clear: both;'}, + '%%HTML_CONTENT%%', + (link || linkNotes) ? m('p.double', {style: 'text-align: center; clear: both;'}, link ? m('a.chaptercomments', {href: link + '#comment_list'}, 'Read chapter comments online') : null, linkNotes ? m('a.chaptercomments', {href: linkNotes}, 'Read author\'s note') : null - ) + ) : null ]) ]) )) + chapterPage = chapterPage.replace('%%HTML_CONTENT%%', '\n' + render(sections) + '\n') + resolve(chapterPage) }) } @@ -339,7 +341,7 @@ export function createTitlePage (ffc) { 'This story is a sequel to ', m('a', {href: ffc.storyInfo.prequel.url}, ffc.storyInfo.prequel.title) ]), m('hr')] : null, - m('#description', m.trust(ffc.storyInfo.description)), + m('#description', '%%HTML_CONTENT%%'), m('.bottom', [ m('span', {className: 'completed-status-' + ffc.storyInfo.status.toLowerCase()}, ffc.storyInfo.status), ffc.storyInfo.publishDate && infoBox('First Published', prettyDate(new Date(ffc.storyInfo.publishDate * 1000))), @@ -355,6 +357,7 @@ export function createTitlePage (ffc) { ]) ]) )) + titlePage = titlePage.replace('%%HTML_CONTENT%%', '\n' + ffc.storyInfo.description + '\n') // console.log(titlePage) return titlePage } diff --git a/src/test.xhtml b/src/test.xhtml new file mode 100644 index 0000000..572110a --- /dev/null +++ b/src/test.xhtml @@ -0,0 +1,125 @@ +

This chapter is designed to test the capabilities of various ePub extraction tools against each BBCode tag supported by FIMFiction.net. First of all, note that this paragraph begins with a tab indent—many tools will remove this. Next, here is the set of non-ANSI characters that I frequently use in my stories: “” ‘’ — … (smart double quotes, smart single quotes, em-dash, and ellipses).

+

Next are the tags that should work in-line: [b] + bold[/b], [i] + italics[/i], [u] + underline[/u], [s] + strikethrough[/s], [smcaps] + small caps[/smcaps], [spoiler] + spoiler text[/spoiler], [url] + hyperlink[/url], [email] + user@server.com[/email], and finally an in-line image: [img] + Image[/img]. +

+

+ There's a known bug in translating FIMFiction stories where consecutive italicized paragraphs lose the italics after the first paragraph. Well, this paragraph is supposed to be italicized. +

+

+ And so is this one. +

+

+ And ending with this one. +

+

Let’s quickly step through all of the named color tags: + red, + silver, + orange, + yellow, + brown, + green, + olive, + cornflowerblue, + cyan, + purple, + pink, + hotpink, + lime, + white (white), + lightgrey, + indigo, + darkblue, + lightblue, + blue, + gold, + navy, + chartreuse, and + teal. Here are some of the colors I use to code character's thoughts in my “Thought Experiments” series: + #0077D0 for Vinyl Scratch, + #60BB50 for Spike, + purple for Twilight Sparkle, + hotpink for Pinkie Pie, and + darkblue for Rainbow Dash. +

+

Size can be indicated by either an absolute number, or in "ems", which is a percentage scaling:

+

[size=24] + Size 24, which should be normal-size text for default settings[/size] +

+

[size=12] + Size 12, which should be half-size text for default settings[/size] +

+

[size=48] + Size 48, which should be double-size text for default settings[/size] +

+

[size=1em] + 1 em text[/size] +

+

[size=.5em] + 0.5 em text[/size] +

+

[size=2em] + 2 em text[/size] +

+

+
+

Just above this paragraph should be a horizontal rule, or [hr] tag.

+

+

[center]Centered text[/center]

+

+
+[right]Right-aligned text[/right] +
+

+
+[quote] This is a quote. + + +

One big problem I've found with ePub extractors is handling multiple-paragraph quotes. This paragraph should still be inside the above quote tag.

+

+

[center]Centered in the quote.[/center]

+

[/quote]

+
+

+
+

Here's an image all by itself:

+

+ Image +

+

Here's a YouTube video:

+

+
+ + d.notive - Vicious Lies (Depeche Mode Imitation) + +
+ d.notive - Vicious Lies (Depeche Mode Imitation) on YouTube +
+
+

+
+

+
+[left_insert]This creates left-aligned text that wraps at the center of the screen. Here's some + lorum ipsum to demonstrate line-wrapping: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. + + +

Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.[/left_insert]

+
+

+
+[right_insert]This creates left-aligned text starting at the center of the screen. Here's some + lorum ipsum to demonstrate line-wrapping: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. + + +

Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.[/right_insert]

+
+

+
\ No newline at end of file diff --git a/src/testkepub.js b/src/testkepub.js new file mode 100644 index 0000000..7d4214b --- /dev/null +++ b/src/testkepub.js @@ -0,0 +1,18 @@ +const cheerio = require('cheerio') +const fs = require('fs') + +let content = fs.readFileSync('test.xhtml', 'utf8') + +let $ = cheerio.load(content, {xmlMode: true}) + +let elements = $('p, h1, h2, h3, h4, h5, h6') + +elements.each((i, element) => { + let el = $(element) + let newTag = $('') + newTag.attr('id', 'kobo.' + i + '.1') + newTag.append(el.contents()) + el.append(newTag) +}) + +console.log($.xml())