1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-15 18:56:22 +00:00

improvement: refactor buildStyle to NamedParameters style, and add some jsdoc

This commit is contained in:
hikerpig
2019-07-21 15:24:26 +08:00
parent addf9b920f
commit c2a26a8547

View File

@@ -47,7 +47,21 @@ const CSS_FILES = [
] ]
const win = global.process.platform === 'win32' const win = global.process.platform === 'win32'
function buildStyle ( /**
* @param {Object} opts
* @param {String} opts.fontFamily
* @param {Numberl} opts.fontSize
* @param {String} opts.codeBlockFontFamily
* @param {String} opts.theme
* @param {Boolean} [opts.lineNumber] Should show line number
* @param {Boolean} [opts.scrollPastEnd]
* @param {Boolean} [opts.optimizeOverflowScroll] Should tweak body style to optimize overflow scrollbar display
* @param {Boolean} [opts.allowCustomCSS] Should add custom css
* @param {String} [opts.customCSS] Will be added to bottom, only if `opts.allowCustomCSS` is truthy
* @returns {String}
*/
function buildStyle (opts) {
const {
fontFamily, fontFamily,
fontSize, fontSize,
codeBlockFontFamily, codeBlockFontFamily,
@@ -57,7 +71,7 @@ function buildStyle (
theme, theme,
allowCustomCSS, allowCustomCSS,
customCSS customCSS
) { } = opts
return ` return `
@font-face { @font-face {
font-family: 'Lato'; font-family: 'Lato';
@@ -338,17 +352,16 @@ export default class MarkdownPreview extends React.Component {
customCSS customCSS
} = this.getStyleParams() } = this.getStyleParams()
const inlineStyles = buildStyle( const inlineStyles = buildStyle({
fontFamily, fontFamily,
fontSize, fontSize,
codeBlockFontFamily, codeBlockFontFamily,
lineNumber, lineNumber,
scrollPastEnd, scrollPastEnd,
false,
theme, theme,
allowCustomCSS, allowCustomCSS,
customCSS customCSS
) })
let body = this.markdown.render(noteContent) let body = this.markdown.render(noteContent)
body = attachmentManagement.fixLocalURLS( body = attachmentManagement.fixLocalURLS(
body, body,
@@ -668,17 +681,17 @@ export default class MarkdownPreview extends React.Component {
'codeTheme' 'codeTheme'
).href = this.GetCodeThemeLink(codeBlockTheme) ).href = this.GetCodeThemeLink(codeBlockTheme)
this.getWindow().document.getElementById('style').innerHTML = buildStyle( this.getWindow().document.getElementById('style').innerHTML = buildStyle({
fontFamily, fontFamily,
fontSize, fontSize,
codeBlockFontFamily, codeBlockFontFamily,
lineNumber, lineNumber,
scrollPastEnd, scrollPastEnd,
true, optimizeOverflowScroll: true,
theme, theme,
allowCustomCSS, allowCustomCSS,
customCSS, customCSS
) })
this.getWindow().document.documentElement.style.overflowY = 'hidden' this.getWindow().document.documentElement.style.overflowY = 'hidden'
} }