diff --git a/package.json b/package.json index 986228b..cdc11d8 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "pretty-data": "^0.40.0", "request": "^2.85.0", "sanitize-filename": "^1.6.0", + "smartypants": "0.0.5", "syllable": "^3.0.0", "twemoji": "^2.5.0", "zero-fill": "^2.2.3" diff --git a/src/FimFic2Epub.js b/src/FimFic2Epub.js index 83d22fd..7db4c19 100644 --- a/src/FimFic2Epub.js +++ b/src/FimFic2Epub.js @@ -10,6 +10,7 @@ import fileType from 'file-type' import isSvg from 'is-svg' import sizeOf from 'image-size' import EventEmitter from 'events' +import { smartypantsu } from 'smartypants' import { cleanMarkup } from './cleanMarkup' import fetch from './fetch' @@ -89,6 +90,7 @@ class FimFic2Epub extends EventEmitter { this.storyId = FimFic2Epub.getStoryId(storyId) this.defaultOptions = { + typogrify: true, addCommentsLink: true, includeAuthorNotes: true, useAuthorNotesIndex: false, @@ -363,11 +365,16 @@ class FimFic2Epub extends EventEmitter { for (let i = 0; i < this.chapters.length; i++) { let ch = this.storyInfo.chapters[i] let chapter = this.chapters[i] + let content = chapter.content + if (this.options.typogrify) { + content = smartypantsu(content.replace(/"/g, '"'), 'qde') + } + chain = chain.then(template.createChapter.bind(null, { title: this.options.addChapterHeadings ? ch.title : null, link: this.options.addCommentsLink ? ch.link : null, linkNotes: this.options.includeAuthorNotes && this.options.useAuthorNotesIndex && chapter.notes ? 'note_' + zeroFill(3, i + 1) + '.xhtml' : null, - content: chapter.content, + content: content, notes: !this.options.useAuthorNotesIndex ? chapter.notes : '', notesFirst: chapter.notesFirst })).then((html) => { diff --git a/src/cli.js b/src/cli.js index 443d7cf..1a0b983 100755 --- a/src/cli.js +++ b/src/cli.js @@ -6,6 +6,7 @@ const args = require('commander') .option('-d, --dir ', 'Directory to store ebook in. Is prepended to filename') .option('-t, --title ', 'Set the title of the story') .option('-a, --author ', 'Set the author of the story') + .option('-T, --no-typogrify', 'Disable typographic fixes (smartypants)') .option('-c, --no-comments-link', 'Don\'t add link to online comments') .option('-H, --no-headings', 'Don\'t add headings to chapters') .option('-r, --no-reading-ease', 'Don\'t calculate Flesch reading ease') @@ -39,6 +40,7 @@ const path = require('path') const STORY_ID = args.args[0] const ffc = new FimFic2Epub(STORY_ID, { + typogrify: !!args.typogrify, addCommentsLink: !!args.commentsLink, includeAuthorNotes: !!args.notes, useAuthorNotesIndex: !!args.notesIndex, diff --git a/src/main.js b/src/main.js index 6d4cb95..bcab4c5 100644 --- a/src/main.js +++ b/src/main.js @@ -129,6 +129,7 @@ let dialog = { this.author = prop('') this.description = prop('') this.subjects = prop([]) + this.typogrify = prop(ffc.options.typogrify) this.addCommentsLink = prop(ffc.options.addCommentsLink) this.includeAuthorNotes = prop(ffc.options.includeAuthorNotes) this.useAuthorNotesIndex = prop(ffc.options.useAuthorNotesIndex) @@ -250,6 +251,7 @@ let dialog = { ], ctrl.paragraphStyle())) )), m('tr', m('td.label', ''), m('td', {colspan: 2}, + m(checkbox, {checked: ctrl.typogrify(), onchange: m.withAttr('checked', ctrl.typogrify)}, 'Apply typographic fixes (smartypants)'), m(checkbox, {checked: ctrl.addChapterHeadings(), onchange: m.withAttr('checked', ctrl.addChapterHeadings)}, 'Add chapter headings'), m(checkbox, {checked: ctrl.addCommentsLink(), onchange: m.withAttr('checked', ctrl.addCommentsLink)}, 'Add link to online comments (at the end of chapters)'), m(checkbox, {checked: ctrl.includeAuthorNotes(), onchange: m.withAttr('checked', ctrl.includeAuthorNotes)}, 'Include author\'s notes'), @@ -311,6 +313,7 @@ function createEpub (model) { ffc.setTitle(model.title()) ffc.setAuthorName(model.author()) ffc.storyInfo.short_description = model.description() + ffc.options.typogrify = model.typogrify() ffc.options.addCommentsLink = model.addCommentsLink() ffc.options.includeAuthorNotes = model.includeAuthorNotes() ffc.options.useAuthorNotesIndex = model.useAuthorNotesIndex()