mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 01:36:22 +00:00
add href, id, name transform for secure navigation
This commit is contained in:
@@ -3,6 +3,7 @@ import markdown from '../lib/markdown'
|
|||||||
import ReactDOM from 'react-dom'
|
import ReactDOM from 'react-dom'
|
||||||
import sanitizeHtml from '@rokt33r/sanitize-html'
|
import sanitizeHtml from '@rokt33r/sanitize-html'
|
||||||
import hljs from 'highlight.js'
|
import hljs from 'highlight.js'
|
||||||
|
import _ from 'lodash'
|
||||||
|
|
||||||
const electron = require('electron')
|
const electron = require('electron')
|
||||||
const shell = electron.shell
|
const shell = electron.shell
|
||||||
@@ -21,14 +22,29 @@ const sanitizeOpts = {
|
|||||||
},
|
},
|
||||||
allowedAttributes: {
|
allowedAttributes: {
|
||||||
a: ['href', 'data-key'],
|
a: ['href', 'data-key'],
|
||||||
img: [ 'src' ]
|
img: [ 'src' ],
|
||||||
|
'*': ['id', 'name']
|
||||||
|
},
|
||||||
|
transformTags: {
|
||||||
|
'*': function (tagName, attribs) {
|
||||||
|
let href = attribs.href
|
||||||
|
if (_.isString(href) && href.match(/^#.+$/)) attribs.href = href.replace(/^#/, '#md-anchor-')
|
||||||
|
if (attribs.id) attribs.id = 'md-anchor-' + attribs.id
|
||||||
|
if (attribs.name) attribs.name = 'md-anchor-' + attribs.name
|
||||||
|
return {
|
||||||
|
tagName: tagName,
|
||||||
|
attribs: attribs
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleAnchorClick (e) {
|
function handleAnchorClick (e) {
|
||||||
|
if (e.target.attributes.href && e.target.attributes.href.nodeValue.match(/#.+/)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
console.log(e.target.href)
|
|
||||||
shell.openExternal(e.target.href)
|
shell.openExternal(e.target.href)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export default class ArticleEditor extends React.Component {
|
|||||||
firstVisibleRow: null
|
firstVisibleRow: null
|
||||||
}, function () {
|
}, function () {
|
||||||
let previewEl = ReactDOM.findDOMNode(this.refs.preview)
|
let previewEl = ReactDOM.findDOMNode(this.refs.preview)
|
||||||
previewEl.scrollTop = 0
|
if (previewEl) previewEl.scrollTop = 0
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
const electron = require('electron')
|
const electron = require('electron')
|
||||||
const ipc = electron.ipcRenderer
|
const ipc = electron.ipcRenderer
|
||||||
import React, { PropTypes } from 'react'
|
import React, { PropTypes } from 'react'
|
||||||
|
import HomePage from './HomePage'
|
||||||
|
|
||||||
export default class MainContainer extends React.Component {
|
export default class MainContainer extends React.Component {
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
@@ -24,7 +25,7 @@ export default class MainContainer extends React.Component {
|
|||||||
{this.state.updateAvailable ? (
|
{this.state.updateAvailable ? (
|
||||||
<button onClick={this.updateApp} className='appUpdateButton'><i className='fa fa-cloud-download'/> Update available!</button>
|
<button onClick={this.updateApp} className='appUpdateButton'><i className='fa fa-cloud-download'/> Update available!</button>
|
||||||
) : null}
|
) : null}
|
||||||
{this.props.children}
|
<HomePage/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
import { Provider } from 'react-redux'
|
import { Provider } from 'react-redux'
|
||||||
import { Router, Route, IndexRoute } from 'react-router'
|
|
||||||
import MainPage from './MainPage'
|
import MainPage from './MainPage'
|
||||||
import HomePage from './HomePage'
|
|
||||||
import store from './store'
|
import store from './store'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import ReactDOM from 'react-dom'
|
import ReactDOM from 'react-dom'
|
||||||
@@ -40,17 +38,11 @@ ipc.on('open-finder', function () {
|
|||||||
activityRecord.emit('FINDER_OPEN')
|
activityRecord.emit('FINDER_OPEN')
|
||||||
})
|
})
|
||||||
|
|
||||||
let routes = (
|
|
||||||
<Route path='/' component={MainPage}>
|
|
||||||
<IndexRoute name='home' component={HomePage}/>
|
|
||||||
</Route>
|
|
||||||
)
|
|
||||||
|
|
||||||
let el = document.getElementById('content')
|
let el = document.getElementById('content')
|
||||||
ReactDOM.render((
|
ReactDOM.render((
|
||||||
<div>
|
<div>
|
||||||
<Provider store={store}>
|
<Provider store={store}>
|
||||||
<Router>{routes}</Router>
|
<MainPage/>
|
||||||
</Provider>
|
</Provider>
|
||||||
</div>
|
</div>
|
||||||
), el, function () {
|
), el, function () {
|
||||||
|
|||||||
@@ -64,7 +64,6 @@
|
|||||||
"react": "^0.14.3",
|
"react": "^0.14.3",
|
||||||
"react-dom": "^0.14.3",
|
"react-dom": "^0.14.3",
|
||||||
"react-redux": "^4.0.6",
|
"react-redux": "^4.0.6",
|
||||||
"react-router": "^1.0.0-rc1",
|
|
||||||
"redux": "^3.0.5",
|
"redux": "^3.0.5",
|
||||||
"standard": "^5.3.1",
|
"standard": "^5.3.1",
|
||||||
"style-loader": "^0.12.4",
|
"style-loader": "^0.12.4",
|
||||||
|
|||||||
Reference in New Issue
Block a user