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

Fix URIs decoded with mdurl

This PR mitigates #918 by retroactively replacing link text decoded by mdurl with the original link.
This commit is contained in:
Aquib Master
2017-10-14 19:01:04 +13:00
parent c429fc6b2c
commit 31daec5fe2
3 changed files with 275 additions and 263 deletions

View File

@@ -10,6 +10,7 @@ import eventEmitter from 'browser/main/lib/eventEmitter'
import fs from 'fs' import fs from 'fs'
import htmlTextHelper from 'browser/lib/htmlTextHelper' import htmlTextHelper from 'browser/lib/htmlTextHelper'
import copy from 'copy-to-clipboard' import copy from 'copy-to-clipboard'
import mdurl from 'mdurl'
const { remote } = require('electron') const { remote } = require('electron')
const { app } = remote const { app } = remote
@@ -183,6 +184,14 @@ export default class MarkdownPreview extends React.Component {
}) })
} }
fixDecodedURI(node) {
const { innerText, href } = node
node.innerText = mdurl.decode(href) === innerText ?
href :
innerText;
}
componentDidMount () { componentDidMount () {
this.refs.root.setAttribute('sandbox', 'allow-scripts') this.refs.root.setAttribute('sandbox', 'allow-scripts')
this.refs.root.contentWindow.document.body.addEventListener('contextmenu', this.contextMenuHandler) this.refs.root.contentWindow.document.body.addEventListener('contextmenu', this.contextMenuHandler)
@@ -279,6 +288,7 @@ export default class MarkdownPreview extends React.Component {
}) })
_.forEach(this.refs.root.contentWindow.document.querySelectorAll('a'), (el) => { _.forEach(this.refs.root.contentWindow.document.querySelectorAll('a'), (el) => {
this.fixDecodedURI(el)
el.addEventListener('click', this.anchorClickHandler) el.addEventListener('click', this.anchorClickHandler)
}) })

View File

@@ -70,6 +70,7 @@
"markdown-it-multimd-table": "^2.0.1", "markdown-it-multimd-table": "^2.0.1",
"markdown-it-named-headers": "^0.0.4", "markdown-it-named-headers": "^0.0.4",
"md5": "^2.0.0", "md5": "^2.0.0",
"mdurl": "^1.0.1",
"mixpanel": "^0.4.1", "mixpanel": "^0.4.1",
"moment": "^2.10.3", "moment": "^2.10.3",
"node-ipc": "^8.1.0", "node-ipc": "^8.1.0",

527
yarn.lock

File diff suppressed because it is too large Load Diff