Skip to content

Commit

Permalink
better md files check
Browse files Browse the repository at this point in the history
  • Loading branch information
bniwredyc committed Dec 2, 2024
1 parent f9de9d9 commit fd9c330
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions check-md-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
}
});
Expand Down

0 comments on commit fd9c330

Please sign in to comment.