mirror of
https://github.com/marktext/marktext.git
synced 2025-05-02 08:03:02 +08:00
parent
34e4a22857
commit
dd14385cb4
@ -415,15 +415,20 @@ ipcMain.on('mt::format-link-click', (e, { data, dirname }) => {
|
||||
return
|
||||
}
|
||||
|
||||
const href = data.href || data.text
|
||||
if (URL_REG.test(href)) {
|
||||
shell.openExternal(href)
|
||||
const urlCandidate = data.href || data.text
|
||||
if (URL_REG.test(urlCandidate)) {
|
||||
shell.openExternal(urlCandidate)
|
||||
return
|
||||
} else if (/^[a-z0-9]+:\/\//i.test(href)) {
|
||||
} else if (/^[a-z0-9]+:\/\//i.test(urlCandidate)) {
|
||||
// Prevent other URLs.
|
||||
return
|
||||
}
|
||||
|
||||
const href = data.href
|
||||
if (!href) {
|
||||
return
|
||||
}
|
||||
|
||||
let pathname = null
|
||||
if (path.isAbsolute(href)) {
|
||||
pathname = href
|
||||
@ -432,6 +437,7 @@ ipcMain.on('mt::format-link-click', (e, { data, dirname }) => {
|
||||
}
|
||||
|
||||
if (pathname) {
|
||||
pathname = path.normalize(pathname)
|
||||
if (isMarkdownFile(pathname)) {
|
||||
const win = BrowserWindow.fromWebContents(e.sender)
|
||||
openFileOrFolder(win, pathname)
|
||||
|
24
src/muya/lib/utils/markdownFile.js
Executable file
24
src/muya/lib/utils/markdownFile.js
Executable file
@ -0,0 +1,24 @@
|
||||
// __MARKTEXT_ONLY__
|
||||
|
||||
const MARKDOWN_EXTENSIONS = Object.freeze([
|
||||
'markdown',
|
||||
'mdown',
|
||||
'mkdn',
|
||||
'md',
|
||||
'mkd',
|
||||
'mdwn',
|
||||
'mdtxt',
|
||||
'mdtext',
|
||||
'text',
|
||||
'txt'
|
||||
])
|
||||
|
||||
/**
|
||||
* Returns true if the filename matches one of the markdown extensions allowed in MarkText.
|
||||
*
|
||||
* @param {string} filename Path or filename
|
||||
*/
|
||||
export const hasMarkdownExtension = filename => {
|
||||
if (!filename || typeof filename !== 'string') return false
|
||||
return MARKDOWN_EXTENSIONS.some(ext => filename.toLowerCase().endsWith(`.${ext}`))
|
||||
}
|
@ -1,8 +1,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' && isValidAttribute('a', 'href', rawLink)) {
|
||||
return 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 ''
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user