mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 09:46:22 +00:00
added export escape html config
This commit is contained in:
@@ -15,6 +15,7 @@ import copy from 'copy-to-clipboard'
|
||||
import mdurl from 'mdurl'
|
||||
import exportNote from 'browser/main/lib/dataApi/exportNote'
|
||||
import { escapeHtmlCharacters } from 'browser/lib/utils'
|
||||
import ConfigManager from 'browser/main/lib/ConfigManager'
|
||||
|
||||
const { remote } = require('electron')
|
||||
const attachmentManagement = require('../main/lib/dataApi/attachmentManagement')
|
||||
@@ -218,7 +219,7 @@ export default class MarkdownPreview extends React.Component {
|
||||
const {fontFamily, fontSize, codeBlockFontFamily, lineNumber, codeBlockTheme, scrollPastEnd, theme} = this.getStyleParams()
|
||||
|
||||
const inlineStyles = buildStyle(fontFamily, fontSize, codeBlockFontFamily, lineNumber, scrollPastEnd, theme)
|
||||
let body = this.markdown.render(escapeHtmlCharacters(noteContent))
|
||||
let body = this.markdown.render(ConfigManager.get().exports.escapeHtml ? escapeHtmlCharacters(noteContent) : noteContent)
|
||||
|
||||
const files = [this.GetCodeThemeLink(codeBlockTheme), ...CSS_FILES]
|
||||
const attachmentsAbsolutePaths = attachmentManagement.getAbsolutePathsOfAttachmentsInContent(noteContent, this.props.storagePath)
|
||||
|
||||
@@ -65,6 +65,9 @@ export const DEFAULT_CONFIG = {
|
||||
token: '',
|
||||
username: '',
|
||||
password: ''
|
||||
},
|
||||
exports: {
|
||||
escapeHtml: true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
120
browser/main/modals/PreferencesModal/Export.js
Normal file
120
browser/main/modals/PreferencesModal/Export.js
Normal file
@@ -0,0 +1,120 @@
|
||||
import React from 'react'
|
||||
import ConfigManager from 'browser/main/lib/ConfigManager'
|
||||
import i18n from 'browser/lib/i18n'
|
||||
import styles from './ConfigTab.styl'
|
||||
import CSSModules from 'browser/lib/CSSModules'
|
||||
import store from 'browser/main/store'
|
||||
|
||||
const electron = require('electron')
|
||||
const ipc = electron.ipcRenderer
|
||||
|
||||
class Export extends React.Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
this.state = {
|
||||
config: props.config
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount () {
|
||||
this.handleSettingDone = () => {
|
||||
this.setState({ExportAlert: {
|
||||
type: 'success',
|
||||
message: i18n.__('Successfully applied!')
|
||||
}})
|
||||
}
|
||||
this.handleSettingError = (err) => {
|
||||
this.setState({ExportAlert: {
|
||||
type: 'error',
|
||||
message: err.message != null ? err.message : i18n.__('Error occurs!')
|
||||
}})
|
||||
}
|
||||
ipc.addListener('APP_SETTING_DONE', this.handleSettingDone)
|
||||
ipc.addListener('APP_SETTING_ERROR', this.handleSettingError)
|
||||
}
|
||||
|
||||
componentWillUnmount () {
|
||||
ipc.removeListener('APP_SETTING_DONE', this.handleSettingDone)
|
||||
ipc.removeListener('APP_SETTING_ERROR', this.handleSettingError)
|
||||
}
|
||||
|
||||
handleUIChange (e) {
|
||||
const newConfig = {
|
||||
exports: {
|
||||
escapeHtml: this.refs.escapeHtmlExport.checked
|
||||
}
|
||||
}
|
||||
|
||||
this.setState({ config: newConfig }, () => {
|
||||
const { exports } = this.props.config
|
||||
this.currentConfig = { exports }
|
||||
if (_.isEqual(this.currentConfig, this.state.config)) {
|
||||
this.props.haveToSave()
|
||||
} else {
|
||||
this.props.haveToSave({
|
||||
tab: 'EXPORT',
|
||||
type: 'warning',
|
||||
message: i18n.__('You have to save!')
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
handleSaveUIClick (e) {
|
||||
const newConfig = {
|
||||
exports: this.state.config.exports
|
||||
}
|
||||
|
||||
ConfigManager.set(newConfig)
|
||||
|
||||
store.dispatch({
|
||||
type: 'SET_UI',
|
||||
config: newConfig
|
||||
})
|
||||
this.clearMessage()
|
||||
this.props.haveToSave()
|
||||
}
|
||||
|
||||
clearMessage () {
|
||||
_.debounce(() => {
|
||||
this.setState({
|
||||
UiAlert: null
|
||||
})
|
||||
}, 2000)()
|
||||
}
|
||||
|
||||
render () {
|
||||
const ExportAlert = this.state.ExportAlert
|
||||
const ExportAlertElement = ExportAlert != null
|
||||
? <p className={`alert ${ExportAlert.type}`}>
|
||||
{ExportAlert.message}
|
||||
</p>
|
||||
: null
|
||||
return (
|
||||
<div styleName='root'>
|
||||
<div styleName='group'>
|
||||
<div styleName='group-header'>{i18n.__('Export')}</div>
|
||||
|
||||
<div styleName='group-checkBoxSection'>
|
||||
<label>
|
||||
<input onChange={(e) => this.handleUIChange(e)}
|
||||
checked={this.state.config.exports.escapeHtml}
|
||||
ref='escapeHtmlExport'
|
||||
type='checkbox'
|
||||
/>
|
||||
{i18n.__('Escape HTML when export note as HTML')}
|
||||
</label>
|
||||
</div>
|
||||
<div styleName='group-control'>
|
||||
<button styleName='group-control-rightButton'
|
||||
onClick={(e) => this.handleSaveUIClick(e)}>{i18n.__('Save')}
|
||||
</button>
|
||||
{ExportAlertElement}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default CSSModules(Export, styles)
|
||||
@@ -7,6 +7,7 @@ import InfoTab from './InfoTab'
|
||||
import Crowdfunding from './Crowdfunding'
|
||||
import StoragesTab from './StoragesTab'
|
||||
import Blog from './Blog'
|
||||
import Export from './Export'
|
||||
import ModalEscButton from 'browser/components/ModalEscButton'
|
||||
import CSSModules from 'browser/lib/CSSModules'
|
||||
import styles from './PreferencesModal.styl'
|
||||
@@ -86,6 +87,13 @@ class Preferences extends React.Component {
|
||||
haveToSave={alert => this.setState({BlogAlert: alert})}
|
||||
/>
|
||||
)
|
||||
case 'EXPORT':
|
||||
return (
|
||||
<Export
|
||||
config={config}
|
||||
haveToSave={alert => this.setState({ExportAlert: alert})}
|
||||
/>
|
||||
)
|
||||
case 'STORAGES':
|
||||
default:
|
||||
return (
|
||||
@@ -123,7 +131,8 @@ class Preferences extends React.Component {
|
||||
{target: 'UI', label: i18n.__('Interface'), UI: this.state.UIAlert},
|
||||
{target: 'INFO', label: i18n.__('About')},
|
||||
{target: 'CROWDFUNDING', label: i18n.__('Crowdfunding')},
|
||||
{target: 'BLOG', label: i18n.__('Blog'), Blog: this.state.BlogAlert}
|
||||
{target: 'BLOG', label: i18n.__('Blog'), Blog: this.state.BlogAlert},
|
||||
{target: 'EXPORT', label: i18n.__('Export')}
|
||||
]
|
||||
|
||||
const navButtons = tabs.map((tab) => {
|
||||
|
||||
Reference in New Issue
Block a user