2020-02-27 11:19:02 +01:00
|
|
|
'use strict';
|
|
|
|
|
2020-03-17 11:14:28 +01:00
|
|
|
// https://crowdagger.github.io/textes/articles/heuristique.html
|
|
|
|
|
2020-02-27 11:19:02 +01:00
|
|
|
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 => {
|
|
|
|
for (const page of pages) {
|
2022-02-02 17:41:15 +01:00
|
|
|
page.content = rt(page.content)
|
2020-02-27 11:19:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
savePages(pages);
|
|
|
|
})
|