mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-03 08:35:29 +02:00
16 lines
580 B
TypeScript
16 lines
580 B
TypeScript
// 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();
|
|
|
|
if (str.startsWith('data:image/svg+xml,') || str.startsWith('data:image/svg+xml;utf8,')) {
|
|
return true;
|
|
}
|
|
|
|
return BAD_PROTO_RE.test(str) ? (!!GOOD_DATA_RE.test(str)) : true;
|
|
}
|