@@ -23,6 +23,19 @@ const BROKEN_LINK_REGEX = new RegExp(
23
23
"\\[[^\\]]+\\]\\([^\\)\\s]+\\s[^\\)]+\\)" ,
24
24
"g"
25
25
)
26
+ // This RegEx checks for invalid links in markdown content.
27
+ // The criteria for invalid links are:
28
+ // 1. Exclude images: The link shouldn't be preceded by an exclamation mark
29
+ // 2. Exclude internal links: The URL part of the link shouldn't start with a forward slash
30
+ // 3. Exclude fragment identifiers: The URL part of the link shouldn't start with a hash
31
+ // 4. Exclude typical external links: The URL part of the link shouldn't start with http or https
32
+ // 5. Exclude email links: The URL part of the link shouldn't start with mailto:
33
+ // 6. Exclude PDF links: The URL part of the link shouldn't end with .pdf
34
+ // 7. Exclude links wrapped in angled brackets: The URL part of the link shouldn't start with a <
35
+ const INVALID_LINK_REGEX = new RegExp (
36
+ "(?<!\\!)\\[[^\\]]+\\]\\((?!<|/|#|http|mailto:)[^\\)]*(?<!\\.pdf)\\)" ,
37
+ "g"
38
+ )
26
39
const INCORRECT_PATH_IN_TRANSLATED_MARKDOWN = new RegExp (
27
40
"image: ../../(assets/|../assets/)" ,
28
41
"g"
@@ -204,6 +217,14 @@ function processMarkdown(path: string) {
204
217
// if (!BROKEN_LINK_REGEX.global) break
205
218
}
206
219
220
+ let invalidLinkMatch : RegExpExecArray | null
221
+
222
+ // Check for invalid links
223
+ while ( ( invalidLinkMatch = INVALID_LINK_REGEX . exec ( markdownFile ) ) ) {
224
+ const lineNumber = getLineNumber ( markdownFile , invalidLinkMatch . index )
225
+ console . warn ( `Invalid link found: ${ path } :${ lineNumber } ` )
226
+ }
227
+
207
228
let incorrectImagePathMatch : RegExpExecArray | null
208
229
209
230
// Todo: refactor to simply check if the image exists relative to the path
0 commit comments