diff --git a/src/cleanMarkup.js b/src/cleanMarkup.js index 3069ffb..237ffb6 100644 --- a/src/cleanMarkup.js +++ b/src/cleanMarkup.js @@ -13,13 +13,18 @@ if (!isNode) { tidy = process.tidy } -let matchYoutube = /
') html = html.replace(/<\/center>/g, '
') + // replace HTML non-breaking spaces with normal spaces + html = html.replace(/ /g, ' ') + + html = fixParagraphIndent(html) + + html = fixDoubleSpacing(html) + let cache = new Map() let completeCount = 0 @@ -41,6 +46,7 @@ export function cleanMarkup (html, callback) { }) } + let matchYoutube = /', '') html = html.replace('', '') - html = fixDoubleSpacing(html) - html = tidy(`\n` + html, tidyOptions) callback(html) @@ -93,3 +97,19 @@ export function fixDoubleSpacing (html) { html = html.replace(/\s+(<\/[a-z][^>]*>)\s+/g, '$1 ') return html } + +export function fixParagraphIndent (html) { + // from FimFictionConverter by Nyerguds// from FimFictionConverter by Nyerguds + let fixIndent = 2 + if (fixIndent > 0) { + // only trigger indenting when finding as many whitespace characters in a row as indicated by the FixIndent setting. + + // Add indented class, with the search keeping into account that there could be opening tags behind the p tag. + html = html.replace(new RegExp('((<([^>]+)>)*)\\s{' + fixIndent + '}\\s*', 'g'), '
$1') + html = html.replace(new RegExp('
((<([^>]+)>)*)\\s{' + fixIndent + '}\\s*', 'g'), '
$3') + + // Cleanup of remaining start whitespace in already indented paragraphs: + html = html.replace(/
]*)>((<[^>]+>)*)\\s+/g, '
$2') + } + return html +} diff --git a/src/style.styl b/src/style.styl index e0caa68..1631190 100644 --- a/src/style.styl +++ b/src/style.styl @@ -35,6 +35,9 @@ h1, h2, h3, h4, h5, h6 { font-weight: normal; margin: 0; } + & + p.indented { + text-indent: 0; + } } img { diff --git a/src/templates.js b/src/templates.js index 41cca5d..55a0435 100644 --- a/src/templates.js +++ b/src/templates.js @@ -24,6 +24,8 @@ function prettyDate (d) { } export function createChapter (ch, html, callback) { + let trimWhitespace = /^\s*(
)+|(
)+\s*$/ig + let authorNotesPos = html.indexOf('