mirror of
https://github.com/marktext/marktext.git
synced 2025-05-02 17:31:26 +08:00
parent
34e4a22857
commit
dd14385cb4
@ -415,15 +415,20 @@ ipcMain.on('mt::format-link-click', (e, { data, dirname }) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const href = data.href || data.text
|
const urlCandidate = data.href || data.text
|
||||||
if (URL_REG.test(href)) {
|
if (URL_REG.test(urlCandidate)) {
|
||||||
shell.openExternal(href)
|
shell.openExternal(urlCandidate)
|
||||||
return
|
return
|
||||||
} else if (/^[a-z0-9]+:\/\//i.test(href)) {
|
} else if (/^[a-z0-9]+:\/\//i.test(urlCandidate)) {
|
||||||
// Prevent other URLs.
|
// Prevent other URLs.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const href = data.href
|
||||||
|
if (!href) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
let pathname = null
|
let pathname = null
|
||||||
if (path.isAbsolute(href)) {
|
if (path.isAbsolute(href)) {
|
||||||
pathname = href
|
pathname = href
|
||||||
@ -432,6 +437,7 @@ ipcMain.on('mt::format-link-click', (e, { data, dirname }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (pathname) {
|
if (pathname) {
|
||||||
|
pathname = path.normalize(pathname)
|
||||||
if (isMarkdownFile(pathname)) {
|
if (isMarkdownFile(pathname)) {
|
||||||
const win = BrowserWindow.fromWebContents(e.sender)
|
const win = BrowserWindow.fromWebContents(e.sender)
|
||||||
openFileOrFolder(win, pathname)
|
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 { isValidAttribute } from '../utils/dompurify'
|
||||||
|
import { isWin } from '../config' // __MARKTEXT_PATCH__
|
||||||
|
import { hasMarkdownExtension } from './markdownFile' // __MARKTEXT_PATCH__
|
||||||
|
|
||||||
export const sanitizeHyperlink = rawLink => {
|
export const sanitizeHyperlink = rawLink => {
|
||||||
if (rawLink && typeof rawLink === 'string' && isValidAttribute('a', 'href', rawLink)) {
|
if (rawLink && typeof rawLink === 'string') {
|
||||||
return rawLink
|
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 ''
|
return ''
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user