Skip to content

Commit

Permalink
feat: updated links to open in the system's default browser
Browse files Browse the repository at this point in the history
  • Loading branch information
Bin-Huang committed Mar 16, 2023
1 parent 213390b commit 94c842c
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 1 deletion.
30 changes: 30 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/devtools/Block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 94c842c

Please sign in to comment.