Add smartypants option, enabled by default

This commit is contained in:
daniel-j 2018-03-15 17:43:11 +01:00
parent d8d767cc21
commit 82d1f8ea31
4 changed files with 14 additions and 1 deletions

View file

@ -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"

View file

@ -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(/&quot;/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) => {

View file

@ -6,6 +6,7 @@ const args = require('commander')
.option('-d, --dir <path>', 'Directory to store ebook in. Is prepended to filename')
.option('-t, --title <value>', 'Set the title of the story')
.option('-a, --author <value>', '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,

View file

@ -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()