Correction semi-automatique des liens morts
This commit is contained in:
@@ -15,6 +15,14 @@ function trimUnbalancedTrailing(value, openChar, closeChar) {
|
||||
return result;
|
||||
}
|
||||
|
||||
function stripTrailingPunctuation(value) {
|
||||
let result = value;
|
||||
while (/[.,;:!?'"\u2018\u2019\u201C\u201D]+$/.test(result)) {
|
||||
result = result.slice(0, -1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function sanitizeUrlCandidate(raw, options = {}) {
|
||||
if (typeof raw !== "string") return null;
|
||||
let candidate = raw.trim();
|
||||
@@ -24,9 +32,7 @@ function sanitizeUrlCandidate(raw, options = {}) {
|
||||
candidate = candidate.slice(1, -1).trim();
|
||||
}
|
||||
|
||||
while (/[.,;:!?'"\u2018\u2019\u201C\u201D]+$/.test(candidate)) {
|
||||
candidate = candidate.slice(0, -1);
|
||||
}
|
||||
candidate = stripTrailingPunctuation(candidate);
|
||||
|
||||
if (!options.keepTrailingParens) {
|
||||
candidate = trimUnbalancedTrailing(candidate, "(", ")");
|
||||
@@ -39,9 +45,15 @@ function sanitizeUrlCandidate(raw, options = {}) {
|
||||
}
|
||||
candidate = trimUnbalancedTrailing(candidate, "[", "]");
|
||||
candidate = trimUnbalancedTrailing(candidate, "{", "}");
|
||||
candidate = stripTrailingPunctuation(candidate);
|
||||
|
||||
candidate = candidate.replace(/[)]+$/g, (suffix) => {
|
||||
const toTrim = !options.keepTrailingParens ? suffix.length : Math.max(0, suffix.length - 1);
|
||||
return ")".repeat(suffix.length - toTrim);
|
||||
});
|
||||
candidate = candidate.replace(/[*_]+$/, "");
|
||||
candidate = candidate.replace(/\[\^[^\]]*\]$/, "");
|
||||
candidate = stripTrailingPunctuation(candidate);
|
||||
if (!options.keepTrailingParens) {
|
||||
candidate = trimUnbalancedTrailing(candidate, "(", ")");
|
||||
}
|
||||
@@ -201,6 +213,7 @@ async function collectMarkdownLinksFromStream(stream) {
|
||||
lineNumber++;
|
||||
const trimmed = line.trim();
|
||||
|
||||
// Skip YAML front matter entirely; only scan Markdown content
|
||||
if (lineNumber === 1 && trimmed === "---") {
|
||||
inFrontMatter = true;
|
||||
continue;
|
||||
@@ -208,11 +221,8 @@ async function collectMarkdownLinksFromStream(stream) {
|
||||
if (inFrontMatter) {
|
||||
if (trimmed === "---") {
|
||||
inFrontMatter = false;
|
||||
continue;
|
||||
}
|
||||
if (trimmed.startsWith("#")) {
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const url of extractLinksFromText(line)) {
|
||||
|
||||
Reference in New Issue
Block a user