1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 17:56:25 +00:00

add tag link handling with :tag:#tag syntax

This commit is contained in:
AWolf81
2019-05-11 09:30:10 +02:00
parent 9a6ee9d2ef
commit 5f96e314fd
3 changed files with 60 additions and 21 deletions

View File

@@ -23,6 +23,7 @@ import i18n from 'browser/lib/i18n'
import fs from 'fs'
import { render } from 'react-dom'
import Carousel from 'react-image-carousel'
import { hashHistory } from 'react-router'
import ConfigManager from '../main/lib/ConfigManager'
const { remote, shell } = require('electron')
@@ -1015,15 +1016,19 @@ export default class MarkdownPreview extends React.Component {
e.preventDefault()
e.stopPropagation()
const href = e.target.getAttribute('href')
const linkHash = href.split('/').pop()
const rawHref = e.target.getAttribute('href')
const parser = document.createElement('a')
parser.href = e.target.getAttribute('href')
const { href, hash } = parser
const linkHash = hash === '' ? rawHref : hash // needed because we're having special link formats that are removed by parser e.g. :line:10
if (!href) return
if (!rawHref) return // not checked href because parser will create file://... string for [empty link]()
const regexNoteInternalLink = /main.html#(.+)/
if (regexNoteInternalLink.test(linkHash)) {
const targetId = mdurl.encode(linkHash.match(regexNoteInternalLink)[1])
const targetElement = this.refs.root.contentWindow.document.getElementById(
const regexNoteInternalLink = /.*[main.\w]*.html#/
if (regexNoteInternalLink.test(href)) {
const targetId = mdurl.encode(linkHash)
const targetElement = this.refs.root.contentWindow.document.querySelector(
targetId
)
@@ -1061,6 +1066,13 @@ export default class MarkdownPreview extends React.Component {
return
}
const regexIsTagLink = /^:tag:#([\w]+)$/
if (regexIsTagLink.test(rawHref)) {
const tag = rawHref.match(regexIsTagLink)[1]
hashHistory.push(`/tags/${encodeURIComponent(tag)}`)
return
}
// other case
shell.openExternal(href)
}