Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add option to open local links in a new tab (#317) #318

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/components/T3HtmlParser/T3HtmlParser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@ export default {
// If target is still not a link, ignore
if (!(target instanceof HTMLAnchorElement)) { return }
const href = target.getAttribute('href')
// Get link target, if local link, navigate with router link
if (href && href[0] === '/') {
const hrefTarget = target.getAttribute('target')
const isCtrlKeyPressed = event.ctrlKey || event.metaKey
const openInNewTab = (hrefTarget && hrefTarget === '_blank') || isCtrlKeyPressed
// If link is local, not set to open in a new tab,
// and Ctrl (or Cmd) key is not pressed, navigate with router link
if (href && href[0] === '/' && !openInNewTab) {
event.preventDefault()
this.$router.push(href)
}
Expand Down
Loading