From fd9c3306cd82c67b7e7264199c71597348ff08a8 Mon Sep 17 00:00:00 2001 From: Igor Lobanov Date: Mon, 2 Dec 2024 22:35:46 +0100 Subject: [PATCH] better md files check --- check-md-files.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/check-md-files.js b/check-md-files.js index b378816..8b97ed6 100644 --- a/check-md-files.js +++ b/check-md-files.js @@ -3,6 +3,20 @@ const path = require('path'); let errorFound = false; +const prohibitedAmpRegex = /&(?!amp;|lt;|gt;|quot;|apos;)/; + +function checkLine(line) { + if (line.includes('<')) { + return false; + } + + if (line.includes('>')) { + return false; + } + + return !prohibitedAmpRegex.test(line); +} + function checkFiles(dir) { const files = fs.readdirSync(dir); @@ -22,9 +36,8 @@ function checkFiles(dir) { const lines = content.split('\n'); lines.forEach((line, index) => { - // Check for forbidden characters '<' or '>' - if (line.includes('<') || line.includes('>')) { - console.error(`Error in ${filePath}:${index + 1}: Forbidden character '<' or '>' found.`); + if (!checkLine(line)) { + console.error(`Error in ${filePath}:${index + 1}`); errorFound = true; } });