'use strict'; // https://crowdagger.github.io/textes/articles/heuristique.html const path = require('path'); const { loadPages, savePages } = require('./page'); const richtypo = require('richtypo'); const frRules = require('richtypo-rules-fr'); const { definitions } = require('richtypo-rules-common'); console.log('Prepares your texts to publication on web: applies typography rules.'); const openingQuote = '« '; const closingQuote = ' »'; const quotes = text => text .replace( new RegExp(`${definitions.notInTag}(["“«]|“)((${definitions.tag})?(${definitions.dash}${definitions.space})?${definitions.letter})`, 'gmi'), `${openingQuote}$2` ) .replace( new RegExp(`${definitions.notInTag}(["”»]|”)`, 'gmi'), `${closingQuote}` ); const rt = richtypo.default([frRules.default, quotes]); const folder = path.resolve(process.cwd(), 'public') loadPages(folder).then(pages => { const bodyRegex = '(.*)' const regEx = new RegExp(`${bodyRegex}`, "ig") for (const page of pages) { const body = rt(regEx.exec(page.content)[1]) page.content = page.content.replace(bodyRegex, body) } savePages(pages); })