Commit 1fac43f6 by PLN (Algolia)

lint: mur de texte — paragraphe > 80 mots (structurel, pas regex) ; le budget !…

lint: mur de texte — paragraphe > 80 mots (structurel, pas regex) ; le budget ! ignore la syntaxe d'image markdown ; test tiret réparti en paragraphes
parent dc96c91e
/Users/paul-louis.nech/Work/Perso/genuinement
\ No newline at end of file
......@@ -65,8 +65,9 @@ export const CATALOG = [
/\b(delve into|unpack\w*|navigate the complexit\w+|ever-changing landscape|the landscape of|synerg\w+|leverage\w*|holistic approach|it'?s worth noting|lean into|foster a culture|at the end of the day|moving forward|in today'?s world|unlock the potential|harness the power|deep dive|key takeaways|north star|double down on|at scale|boasts a|vibrant|profound)\b/gi],
];
/** Punctuation budgets (ui-sk): 1 tiret cadratin / 500 words, 1 ! / 1000. */
/** Punctuation budgets (ui-sk): 1 tiret cadratin / 500 words, 1 ! / 1000.
* The ! budget ignores Markdown image syntax (`![` — not an exclamation). */
export const BUDGETS = [
{ re: /—/g, perWords: 500, floor: 1, id: 'tiret cadratin', weight: 5 },
{ re: /!/g, perWords: 1000, floor: 1, id: 'exclamation', weight: 5 },
{ re: /!(?!\[)/g, perWords: 1000, floor: 1, id: 'exclamation', weight: 5 },
];
......@@ -57,6 +57,27 @@ function excerpt(text, index) {
return '…' + text.slice(Math.max(0, index - 38), index + 52).replace(/\s+/g, ' ') + '…';
}
/**
* Murs de texte — structural, not a regex: prose paragraphs that don't
* breathe. No SOTA exists for "punch"; paragraph length is the honest proxy
* (readability formulas — Flesch, LIX — score sentences, not blocks). Web
* prose guidance lands around 2–4 sentences; >80 words is a wall, >140 a
* rampart. Tables, lists, headings, blockquotes, code, directives and bare
* figures are exempt — they structure themselves.
*/
const NON_PROSE_LINE = /^\s*(?:[|>#*]|::|!\[|[-+] |\d+\.\s|$)/;
export function heavyParagraphs(text) {
const out = [];
for (const block of text.split(/\n[ \t]*\n+/)) {
const b = block.trim();
if (!b || !b.split('\n').every((l) => !NON_PROSE_LINE.test(l))) continue;
const n = b.split(/\s+/).filter(Boolean).length;
if (n > 80) out.push([n, b]);
}
return out.sort((a, b) => b[0] - a[0]);
}
export function lint(text) {
const words = text.split(/\s+/).filter(Boolean).length;
const outside = outsideTest(quotedRanges(text));
......@@ -82,5 +103,10 @@ export function lint(text) {
excess++;
}
}
for (const [n, b] of heavyParagraphs(text)) {
const w = n > 140 ? 5 : 3;
hits.push({ id: `mur de texte (${n} mots)`, w, at: '…' + b.slice(0, 64).replace(/\s+/g, ' ') + '…' });
score -= w;
}
return { words, hits, masked, score: Math.max(0, score) };
}
......@@ -20,7 +20,9 @@ test('contraste binaire costs 8', () => {
});
test('tiret budget: 1 per 500 words', () => {
const words = Array(600).fill('mot').join(' ');
// 600 words spread over eight 75-word paragraphs: inside the mur de texte
// threshold, so the dash budget alone is under test.
const words = Array.from({ length: 8 }, () => Array(75).fill('mot').join(' ')).join('\n\n');
const r = lint(words + ' — fin.');
assert.equal(r.score, 100); // one dash within budget
const r2 = lint(words + ' — fin — vraiment.');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment