1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-14 02:06:29 +00:00

code style

This commit is contained in:
Max Buranbaev
2018-08-11 16:17:56 +05:00
parent 7fefbd88d0
commit 51e836f32a

View File

@@ -28,9 +28,9 @@ const fileUrl = require('file-url')
const dialog = remote.dialog const dialog = remote.dialog
const markdownStyle = require('!!css!stylus?sourceMap!./markdown.styl')[0][1] const markdownStyle = require('!!css!stylus?sourceMap!./markdown.styl')[0][1]
const appPath = fileUrl(process.env.NODE_ENV === 'production' const appPath = fileUrl(
? app.getAppPath() process.env.NODE_ENV === 'production' ? app.getAppPath() : path.resolve()
: path.resolve()) )
const CSS_FILES = [ const CSS_FILES = [
`${appPath}/node_modules/katex/dist/katex.min.css`, `${appPath}/node_modules/katex/dist/katex.min.css`,
`${appPath}/node_modules/codemirror/lib/codemirror.css` `${appPath}/node_modules/codemirror/lib/codemirror.css`
@@ -256,14 +256,20 @@ export default class MarkdownPreview extends React.Component {
this.exportAsDocument('md', (noteContent, exportTasks) => { this.exportAsDocument('md', (noteContent, exportTasks) => {
let result = noteContent let result = noteContent
if (this.props && this.props.storagePath && this.props.noteKey) { if (this.props && this.props.storagePath && this.props.noteKey) {
const attachmentsAbsolutePaths = attachmentManagement.getAbsolutePathsOfAttachmentsInContent(noteContent, this.props.storagePath) const attachmentsAbsolutePaths = attachmentManagement.getAbsolutePathsOfAttachmentsInContent(
attachmentsAbsolutePaths.forEach((attachment) => { noteContent,
this.props.storagePath
)
attachmentsAbsolutePaths.forEach(attachment => {
exportTasks.push({ exportTasks.push({
src: attachment, src: attachment,
dst: attachmentManagement.DESTINATION_FOLDER dst: attachmentManagement.DESTINATION_FOLDER
}) })
}) })
result = attachmentManagement.removeStorageAndNoteReferences(noteContent, this.props.noteKey) result = attachmentManagement.removeStorageAndNoteReferences(
noteContent,
this.props.noteKey
)
} }
return result return result
}) })
@@ -271,19 +277,38 @@ export default class MarkdownPreview extends React.Component {
handleSaveAsHtml () { handleSaveAsHtml () {
this.exportAsDocument('html', (noteContent, exportTasks) => { this.exportAsDocument('html', (noteContent, exportTasks) => {
const {
fontFamily,
fontSize,
codeBlockFontFamily,
lineNumber,
codeBlockTheme,
scrollPastEnd,
theme,
allowCustomCSS,
customCSS
} = this.getStyleParams()
const {fontFamily, fontSize, codeBlockFontFamily, lineNumber, codeBlockTheme, scrollPastEnd, theme, allowCustomCSS, customCSS} = this.getStyleParams() const inlineStyles = buildStyle(
fontFamily,
const inlineStyles = buildStyle(fontFamily, fontSize, codeBlockFontFamily, lineNumber, scrollPastEnd, theme, allowCustomCSS, customCSS) fontSize,
let body = this.markdown.render(escapeHtmlCharacters(noteContent, { detectCodeBlock: true })) codeBlockFontFamily,
lineNumber,
scrollPastEnd,
theme,
allowCustomCSS,
customCSS
)
let body = this.markdown.render(
escapeHtmlCharacters(noteContent, { detectCodeBlock: true })
)
const files = [this.GetCodeThemeLink(codeBlockTheme), ...CSS_FILES] const files = [this.GetCodeThemeLink(codeBlockTheme), ...CSS_FILES]
const attachmentsAbsolutePaths = attachmentManagement.getAbsolutePathsOfAttachmentsInContent( const attachmentsAbsolutePaths = attachmentManagement.getAbsolutePathsOfAttachmentsInContent(
noteContent, noteContent,
this.props.storagePath this.props.storagePath
) )
files.forEach(file => {
files.forEach((file) => {
if (global.process.platform === 'win32') { if (global.process.platform === 'win32') {
file = file.replace('file:///', '') file = file.replace('file:///', '')
} else { } else {
@@ -368,9 +393,7 @@ export default class MarkdownPreview extends React.Component {
} }
getScrollBarStyle () { getScrollBarStyle () {
const { const { theme } = this.props
theme
} = this.props
switch (theme) { switch (theme) {
case 'dark': case 'dark':
@@ -605,7 +628,10 @@ export default class MarkdownPreview extends React.Component {
this.refs.root.contentWindow.document.body.setAttribute('data-theme', theme) this.refs.root.contentWindow.document.body.setAttribute('data-theme', theme)
const renderedHTML = this.markdown.render(value) const renderedHTML = this.markdown.render(value)
attachmentManagement.migrateAttachments(value, storagePath, noteKey) attachmentManagement.migrateAttachments(value, storagePath, noteKey)
this.refs.root.contentWindow.document.body.innerHTML = attachmentManagement.fixLocalURLS(renderedHTML, storagePath) this.refs.root.contentWindow.document.body.innerHTML = attachmentManagement.fixLocalURLS(
renderedHTML,
storagePath
)
_.forEach( _.forEach(
this.refs.root.contentWindow.document.querySelectorAll( this.refs.root.contentWindow.document.querySelectorAll(
'input[type="checkbox"]' 'input[type="checkbox"]'
@@ -706,12 +732,12 @@ export default class MarkdownPreview extends React.Component {
el.className = 'sequence-error' el.className = 'sequence-error'
el.innerHTML = 'Sequence diagram parse error: ' + e.message el.innerHTML = 'Sequence diagram parse error: ' + e.message
} }
}
}) )
_.forEach( _.forEach(
this.refs.root.contentWindow.document.querySelectorAll('.chart'), this.refs.root.contentWindow.document.querySelectorAll('.chart'),
(el) => { el => {
try { try {
const chartConfig = JSON.parse(el.innerHTML) const chartConfig = JSON.parse(el.innerHTML)
el.innerHTML = '' el.innerHTML = ''
@@ -728,7 +754,7 @@ export default class MarkdownPreview extends React.Component {
) )
_.forEach( _.forEach(
this.refs.root.contentWindow.document.querySelectorAll('.mermaid'), this.refs.root.contentWindow.document.querySelectorAll('.mermaid'),
(el) => { el => {
mermaidRender(el, htmlTextHelper.decodeEntities(el.innerHTML), theme) mermaidRender(el, htmlTextHelper.decodeEntities(el.innerHTML), theme)
} }
) )