forked from marktext/marktext
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathurl.js
More file actions
22 lines (20 loc) · 731 Bytes
/
url.js
File metadata and controls
22 lines (20 loc) · 731 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { isValidAttribute } from '../utils/dompurify'
import { isWin } from '../config' // __MARKTEXT_PATCH__
import { hasMarkdownExtension } from './markdownFile' // __MARKTEXT_PATCH__
export const sanitizeHyperlink = rawLink => {
if (rawLink && typeof rawLink === 'string') {
if (isValidAttribute('a', 'href', rawLink)) {
return rawLink
}
// __MARKTEXT_PATCH__
if (isWin && /^[a-zA-Z]:[/\\].+/.test(rawLink) && hasMarkdownExtension(rawLink)) {
// Create and try UNC path on Windows because "C:\file.md" isn't allowed.
const uncPath = `\\\\?\\${rawLink}`
if (isValidAttribute('a', 'href', uncPath)) {
return uncPath
}
}
// END __MARKTEXT_PATCH__
}
return ''
}