2021-01-02 18:53:59 +02:00
|
|
|
// enable file link URLs in MarkdownIt. Keeps other URL restrictions of MarkdownIt untouched.
|
|
|
|
// Format [link name](file://...)
|
|
|
|
export default function(url: string) {
|
|
|
|
const BAD_PROTO_RE = /^(vbscript|javascript|data):/;
|
|
|
|
const GOOD_DATA_RE = /^data:image\/(gif|png|jpeg|webp);/;
|
|
|
|
|
|
|
|
// url should be normalized at this point, and existing entities are decoded
|
|
|
|
const str = url.trim().toLowerCase();
|
|
|
|
|
2024-02-02 19:48:26 +02:00
|
|
|
if (str.startsWith('data:image/svg+xml,') || str.startsWith('data:image/svg+xml;utf8,')) {
|
2021-01-02 18:53:59 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-02-21 19:10:53 +02:00
|
|
|
return BAD_PROTO_RE.test(str) ? (!!GOOD_DATA_RE.test(str)) : true;
|
2021-01-02 18:53:59 +02:00
|
|
|
}
|