mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-14 02:06:29 +00:00
extract html contentformatter
This commit is contained in:
@@ -23,7 +23,7 @@ import i18n from 'browser/lib/i18n'
|
|||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import ConfigManager from '../main/lib/ConfigManager'
|
import ConfigManager from '../main/lib/ConfigManager'
|
||||||
|
|
||||||
const { remote, shell } = require('electron')
|
const { remote, shell, BrowserWindow } = require('electron')
|
||||||
const attachmentManagement = require('../main/lib/dataApi/attachmentManagement')
|
const attachmentManagement = require('../main/lib/dataApi/attachmentManagement')
|
||||||
|
|
||||||
const { app } = remote
|
const { app } = remote
|
||||||
@@ -295,64 +295,70 @@ export default class MarkdownPreview extends React.Component {
|
|||||||
this.exportAsDocument('md')
|
this.exportAsDocument('md')
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSaveAsHtml () {
|
htmlContentFormatter (noteContent, exportTasks) {
|
||||||
this.exportAsDocument('html', (noteContent, exportTasks) => {
|
const {
|
||||||
const {
|
fontFamily,
|
||||||
fontFamily,
|
fontSize,
|
||||||
fontSize,
|
codeBlockFontFamily,
|
||||||
codeBlockFontFamily,
|
lineNumber,
|
||||||
lineNumber,
|
codeBlockTheme,
|
||||||
codeBlockTheme,
|
scrollPastEnd,
|
||||||
scrollPastEnd,
|
theme,
|
||||||
theme,
|
allowCustomCSS,
|
||||||
allowCustomCSS,
|
customCSS
|
||||||
customCSS
|
} = this.getStyleParams()
|
||||||
} = this.getStyleParams()
|
|
||||||
|
|
||||||
const inlineStyles = buildStyle(
|
const inlineStyles = buildStyle(
|
||||||
fontFamily,
|
fontFamily,
|
||||||
fontSize,
|
fontSize,
|
||||||
codeBlockFontFamily,
|
codeBlockFontFamily,
|
||||||
lineNumber,
|
lineNumber,
|
||||||
scrollPastEnd,
|
scrollPastEnd,
|
||||||
theme,
|
theme,
|
||||||
allowCustomCSS,
|
allowCustomCSS,
|
||||||
customCSS
|
customCSS
|
||||||
)
|
)
|
||||||
let body = this.markdown.render(noteContent)
|
let body = this.markdown.render(noteContent)
|
||||||
const files = [this.GetCodeThemeLink(codeBlockTheme), ...CSS_FILES]
|
const files = [this.GetCodeThemeLink(codeBlockTheme), ...CSS_FILES]
|
||||||
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 {
|
||||||
file = file.replace('file://', '')
|
file = file.replace('file://', '')
|
||||||
}
|
}
|
||||||
exportTasks.push({
|
exportTasks.push({
|
||||||
src: file,
|
src: file,
|
||||||
dst: 'css'
|
dst: 'css'
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
let styles = ''
|
|
||||||
files.forEach(file => {
|
|
||||||
styles += `<link rel="stylesheet" href="css/${path.basename(file)}">`
|
|
||||||
})
|
|
||||||
|
|
||||||
return `<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name = "viewport" content = "width = device-width, initial-scale = 1, maximum-scale = 1">
|
|
||||||
<style id="style">${inlineStyles}</style>
|
|
||||||
${styles}
|
|
||||||
</head>
|
|
||||||
<body>${body}</body>
|
|
||||||
</html>`
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
let styles = ''
|
||||||
|
files.forEach(file => {
|
||||||
|
styles += `<link rel="stylesheet" href="css/${path.basename(file)}">`
|
||||||
|
})
|
||||||
|
|
||||||
|
return `<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name = "viewport" content = "width = device-width, initial-scale = 1, maximum-scale = 1">
|
||||||
|
<style id="style">${inlineStyles}</style>
|
||||||
|
${styles}
|
||||||
|
</head>
|
||||||
|
<body>${body}</body>
|
||||||
|
</html>`
|
||||||
|
}
|
||||||
|
|
||||||
|
handleSaveAsHtml () {
|
||||||
|
this.exportAsDocument('html', (noteContent, exportTasks) => this.htmlContentFormatter(noteContent, exportTasks))
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSaveAsPdf () {
|
handleSaveAsPdf () {
|
||||||
this.exportAsDocument('pdf', (noteContent, exportTasks) => {
|
this.exportAsDocument('pdf', (noteContent, exportTasks) => {
|
||||||
// Return pdf source
|
// Return pdf source
|
||||||
|
// const doc = new jsPDF()
|
||||||
|
// doc.fromHTML(this.markdown.render(noteContent), 0, 0)
|
||||||
|
// return doc.output()
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user