diff --git a/package-lock.json b/package-lock.json index 02f368ea..c5d60db1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,6 +24,7 @@ "gpt3-tokenizer": "^1.1.5", "highlight.js": "^11.7.0", "markdown-it": "^13.0.1", + "markdown-it-link-attributes": "^4.0.1", "material-ui-popup-state": "^5.0.4", "react": "^18.2.0", "react-dom": "^18.2.0", @@ -40,6 +41,7 @@ "@electron-forge/publisher-github": "^6.0.5", "@types/highlight.js": "^10.1.0", "@types/markdown-it": "^12.2.3", + "@types/markdown-it-link-attributes": "^3.0.1", "@types/react": "^18.0.28", "@types/react-dom": "^18.0.11", "@types/uuid": "^9.0.1", @@ -1995,6 +1997,15 @@ "@types/mdurl": "*" } }, + "node_modules/@types/markdown-it-link-attributes": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@types/markdown-it-link-attributes/-/markdown-it-link-attributes-3.0.1.tgz", + "integrity": "sha512-K8RnNb1q8j7rDOJbMF7AnlhCC/45BjrQ8z3WZWOrvkBIl8u9RXvmBdG/hfpnmK1JhhEZcmFEKWt+ilW1Mly+2Q==", + "dev": true, + "dependencies": { + "@types/markdown-it": "*" + } + }, "node_modules/@types/mdurl": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/@types/mdurl/-/mdurl-1.0.2.tgz", @@ -8349,6 +8360,11 @@ "markdown-it": "bin/markdown-it.js" } }, + "node_modules/markdown-it-link-attributes": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/markdown-it-link-attributes/-/markdown-it-link-attributes-4.0.1.tgz", + "integrity": "sha512-pg5OK0jPLg62H4k7M9mRJLT61gUp9nvG0XveKYHMOOluASo9OEF13WlXrpAp2aj35LbedAy3QOCgQCw0tkLKAQ==" + }, "node_modules/markdown-it/node_modules/entities": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/entities/-/entities-3.0.1.tgz", @@ -14002,6 +14018,15 @@ "@types/mdurl": "*" } }, + "@types/markdown-it-link-attributes": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@types/markdown-it-link-attributes/-/markdown-it-link-attributes-3.0.1.tgz", + "integrity": "sha512-K8RnNb1q8j7rDOJbMF7AnlhCC/45BjrQ8z3WZWOrvkBIl8u9RXvmBdG/hfpnmK1JhhEZcmFEKWt+ilW1Mly+2Q==", + "dev": true, + "requires": { + "@types/markdown-it": "*" + } + }, "@types/mdurl": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/@types/mdurl/-/mdurl-1.0.2.tgz", @@ -18493,6 +18518,11 @@ } } }, + "markdown-it-link-attributes": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/markdown-it-link-attributes/-/markdown-it-link-attributes-4.0.1.tgz", + "integrity": "sha512-pg5OK0jPLg62H4k7M9mRJLT61gUp9nvG0XveKYHMOOluASo9OEF13WlXrpAp2aj35LbedAy3QOCgQCw0tkLKAQ==" + }, "matcher": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/matcher/-/matcher-3.0.0.tgz", diff --git a/package.json b/package.json index c2f8ffe8..be50e540 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "@electron-forge/publisher-github": "^6.0.5", "@types/highlight.js": "^10.1.0", "@types/markdown-it": "^12.2.3", + "@types/markdown-it-link-attributes": "^3.0.1", "@types/react": "^18.0.28", "@types/react-dom": "^18.0.11", "@types/uuid": "^9.0.1", @@ -64,6 +65,7 @@ "gpt3-tokenizer": "^1.1.5", "highlight.js": "^11.7.0", "markdown-it": "^13.0.1", + "markdown-it-link-attributes": "^4.0.1", "material-ui-popup-state": "^5.0.4", "react": "^18.2.0", "react-dom": "^18.2.0", diff --git a/src/devtools/Block.tsx b/src/devtools/Block.tsx index 8822fbac..170e7fda 100644 --- a/src/devtools/Block.tsx +++ b/src/devtools/Block.tsx @@ -23,6 +23,7 @@ import MoreVertIcon from '@mui/icons-material/MoreVert'; import * as wordCount from './utils' import FormatQuoteIcon from '@mui/icons-material/FormatQuote'; import 'github-markdown-css/github-markdown-light.css' +import mila from 'markdown-it-link-attributes' const md = new MarkdownIt({ linkify: true, @@ -41,6 +42,7 @@ const md = new MarkdownIt({ } }); md.use(mdKatex, { blockClass: 'katexmath-block rounded-md p-[10px]', errorColor: ' #cc0000' }) +md.use(mila, { attrs: { target: "_blank", rel: "noopener" } }) export type Message = ChatCompletionRequestMessage & { id: string diff --git a/src/index.ts b/src/index.ts index 17fec688..359a681c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -40,6 +40,14 @@ const onReady = (): void => { if (process.env.NODE_ENV==='development') { mainWindow.webContents.openDevTools(); } + + mainWindow.webContents.setWindowOpenHandler((details) => { + if (details.url.startsWith('http')) { + shell.openExternal(details.url) + return { action: 'deny' } + } + return { action: 'allow' } + }) }; // This method will be called when Electron has finished diff --git a/yarn.lock b/yarn.lock index 4180289d..4547e9c4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1015,7 +1015,14 @@ "resolved" "https://registry.npmjs.org/@types/linkify-it/-/linkify-it-3.0.2.tgz" "version" "3.0.2" -"@types/markdown-it@^12.2.3": +"@types/markdown-it-link-attributes@^3.0.1": + "integrity" "sha512-K8RnNb1q8j7rDOJbMF7AnlhCC/45BjrQ8z3WZWOrvkBIl8u9RXvmBdG/hfpnmK1JhhEZcmFEKWt+ilW1Mly+2Q==" + "resolved" "https://registry.npmjs.org/@types/markdown-it-link-attributes/-/markdown-it-link-attributes-3.0.1.tgz" + "version" "3.0.1" + dependencies: + "@types/markdown-it" "*" + +"@types/markdown-it@*", "@types/markdown-it@^12.2.3": "integrity" "sha512-GKMHFfv3458yYy+v/N8gjufHO6MSZKCOXpZc5GXIWWy8uldwfmPn98vp81gZ5f9SVw8YYBctgfJ22a2d7AOMeQ==" "resolved" "https://registry.npmjs.org/@types/markdown-it/-/markdown-it-12.2.3.tgz" "version" "12.2.3" @@ -4655,6 +4662,11 @@ dependencies: "p-defer" "^1.0.0" +"markdown-it-link-attributes@^4.0.1": + "integrity" "sha512-pg5OK0jPLg62H4k7M9mRJLT61gUp9nvG0XveKYHMOOluASo9OEF13WlXrpAp2aj35LbedAy3QOCgQCw0tkLKAQ==" + "resolved" "https://registry.npmjs.org/markdown-it-link-attributes/-/markdown-it-link-attributes-4.0.1.tgz" + "version" "4.0.1" + "markdown-it@^13.0.1": "integrity" "sha512-lTlxriVoy2criHP0JKRhO2VDG9c2ypWCsT237eDiLqi09rmbKoUetyGHq2uOIRoRS//kfoJckS0eUzzkDR+k2Q==" "resolved" "https://registry.npmjs.org/markdown-it/-/markdown-it-13.0.1.tgz"