Skip to content

Commit 80d1623

Browse files
committed
foot note
1 parent 65e1a39 commit 80d1623

3 files changed

Lines changed: 27 additions & 7 deletions

File tree

browser/components/MarkdownPreview.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ import hljsTheme from 'browser/lib/hljsThemes'
55

66
const markdownStyle = require('!!css!stylus?sourceMap!./markdown.styl')[0][1]
77
const { shell } = require('electron')
8-
const goExternal = function (e) {
9-
e.preventDefault()
10-
e.stopPropagation()
11-
shell.openExternal(e.target.href)
12-
}
138

149
const OSX = global.process.platform === 'darwin'
1510

@@ -27,17 +22,39 @@ export default class MarkdownPreview extends React.Component {
2722
this.contextMenuHandler = (e) => this.handleContextMenu(e)
2823
this.mouseDownHandler = (e) => this.handleMouseDown(e)
2924
this.mouseUpHandler = (e) => this.handleMouseUp(e)
25+
this.goExternalHandler = (e) => this.handlePreviewAnchorClick(e)
26+
}
27+
28+
handlePreviewAnchorClick (e) {
29+
e.preventDefault()
30+
e.stopPropagation()
31+
32+
let href = e.target.getAttribute('href')
33+
if (_.isString(href) && href.match(/^#/)) {
34+
let targetElement = this.refs.root.contentWindow.document.getElementById(href.substring(1, href.length))
35+
if (targetElement != null) {
36+
this.getWindow().scrollTo(0, targetElement.offsetTop)
37+
}
38+
} else {
39+
shell.openExternal(e.target.href)
40+
}
3041
}
3142

3243
handleContextMenu (e) {
3344
this.props.onContextMenu(e)
3445
}
3546

3647
handleMouseDown (e) {
48+
if (e.target != null && e.target.tagName === 'A') {
49+
return null
50+
}
3751
if (this.props.onMouseDown != null) this.props.onMouseDown(e)
3852
}
3953

4054
handleMouseUp (e) {
55+
if (e.target != null && e.target.tagName === 'A') {
56+
return null
57+
}
4158
if (this.props.onMouseUp != null) this.props.onMouseUp(e)
4259
}
4360

@@ -68,7 +85,7 @@ export default class MarkdownPreview extends React.Component {
6885

6986
rewriteIframe () {
7087
Array.prototype.forEach.call(this.refs.root.contentWindow.document.querySelectorAll('a'), (el) => {
71-
el.removeEventListener('click', goExternal)
88+
el.removeEventListener('click', this.goExternalHandler)
7289
})
7390

7491
let { value, fontFamily, fontSize, codeBlockFontFamily, lineNumber, codeBlockTheme } = this.props
@@ -111,7 +128,7 @@ export default class MarkdownPreview extends React.Component {
111128
this.refs.root.contentWindow.document.body.innerHTML = markdown(value)
112129

113130
Array.prototype.forEach.call(this.refs.root.contentWindow.document.querySelectorAll('a'), (el) => {
114-
el.addEventListener('mousedown', goExternal)
131+
el.addEventListener('click', this.goExternalHandler)
115132
})
116133
}
117134

@@ -147,6 +164,7 @@ export default class MarkdownPreview extends React.Component {
147164
style={style}
148165
tabIndex={tabIndex}
149166
ref='root'
167+
onClick={(e) => this.handleClick(e)}
150168
/>
151169
)
152170
}

browser/lib/markdown.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ md.use(math, {
6060
}
6161
})
6262
md.use(require('markdown-it-checkbox'))
63+
md.use(require('markdown-it-footnote'))
6364

6465
let originalRenderToken = md.renderer.renderToken
6566
md.renderer.renderToken = function renderToken (tokens, idx, options) {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"markdown-it": "^6.0.1",
4949
"markdown-it-checkbox": "^1.1.0",
5050
"markdown-it-emoji": "^1.1.1",
51+
"markdown-it-footnote": "^3.0.0",
5152
"md5": "^2.0.0",
5253
"moment": "^2.10.3",
5354
"sander": "^0.5.1",

0 commit comments

Comments
 (0)