diff --git a/src/components/NavigationBar.vue b/src/components/NavigationBar.vue index 14219bbf..6688063f 100644 --- a/src/components/NavigationBar.vue +++ b/src/components/NavigationBar.vue @@ -114,7 +114,8 @@ export default { publishLocations: 'current', }), pagedownButtons() { - return pagedownButtons.map(button => ({ + const buttonShowObj = store.getters['data/computedSettings'].editor.headButtons; + return pagedownButtons.filter(it => buttonShowObj[it.method]).map(button => ({ ...button, titleWithShortcut: `${button.title}${getShortcut(button.method)}`, iconClass: `icon-${button.icon}`, diff --git a/src/data/defaults/defaultSettings.yml b/src/data/defaults/defaultSettings.yml index 27e6ea0f..7502e286 100644 --- a/src/data/defaults/defaultSettings.yml +++ b/src/data/defaults/defaultSettings.yml @@ -17,6 +17,32 @@ editor: monospacedFontOnly: false # 是否显示右上角图标 showInPageButtons: true + # 头部的按钮是否显示独立设置 + headButtons: + # 加粗 + bold: true + # 斜体 + italic: true + # 标题 + heading: true + # 删除线 + strikethrough: true + # 无序列表 + ulist: true + # 有序列表 + olist: true + # 可选列表 + clist: true + # 块引用 + quote: true + # 代码 + code: true + # 表格 + table: true + # 链接 + link: true + # 图片 + image: true # Keyboard shortcuts # See https://craig.is/killing/mice diff --git a/src/data/pagedownButtons.js b/src/data/pagedownButtons.js index 84bcf47f..6dad969d 100644 --- a/src/data/pagedownButtons.js +++ b/src/data/pagedownButtons.js @@ -15,7 +15,7 @@ export default [{ method: 'strikethrough', title: '删除线', icon: 'format-strikethrough', -}, { +// }, { }, { method: 'ulist', title: '无序列表', @@ -28,7 +28,7 @@ export default [{ method: 'clist', title: '可选列表', icon: 'format-list-checks', -}, { +// }, { }, { method: 'quote', title: '块引用', diff --git a/src/services/exportSvc.js b/src/services/exportSvc.js index 877376d4..ac3efde5 100644 --- a/src/services/exportSvc.js +++ b/src/services/exportSvc.js @@ -1,3 +1,4 @@ +import md5 from 'js-md5'; import FileSaver from 'file-saver'; import TemplateWorker from 'worker-loader!./templateWorker.js'; // eslint-disable-line import localDbSvc from './localDbSvc'; @@ -34,6 +35,24 @@ function groupHeadings(headings, level = 1) { return result; } +const getImgBase64 = async (uri) => { + if (uri.indexOf('http://') !== 0 && uri.indexOf('https://') !== 0) { + const currDirNode = store.getters['explorer/selectedNodeFolder']; + const absoluteImgPath = utils.getAbsoluteFilePath(currDirNode, uri); + const md5Id = md5(absoluteImgPath); + const imgItem = await localDbSvc.getImgItem(md5Id); + if (imgItem) { + const potIdx = uri.lastIndexOf('.'); + const suffix = potIdx > -1 ? uri.substring(potIdx + 1) : 'png'; + const mime = `image/${suffix}`; + return `data:${mime};base64,${imgItem.content}`; + } + return ''; + } + return uri; +}; + + const containerElt = document.createElement('div'); containerElt.className = 'hidden-rendering-container'; document.body.appendChild(containerElt); @@ -65,6 +84,28 @@ export default { wrapperElt.parentNode.removeChild(wrapperElt); }); + // 替换相对路径图片为blob图片 + const imgs = Array.prototype.slice.call(containerElt.getElementsByTagName('img')).map((imgElt) => { + let uri = imgElt.attributes.src.nodeValue; + if (uri.indexOf('http://') !== 0 && uri.indexOf('https://') !== 0) { + uri = decodeURIComponent(uri); + imgElt.removeAttribute('src'); + return { imgElt, uri }; + } + return { imgElt }; + }); + const loadedPromises = imgs.map(it => new Promise((resolve, reject) => { + if (!it.imgElt.src && it.uri) { + getImgBase64(it.uri).then((newUrl) => { + it.imgElt.src = newUrl; + resolve(); + }, () => reject(new Error('加载当前空间图片出错'))); + return; + } + resolve(); + })); + await Promise.all(loadedPromises); + // Make TOC const headings = containerElt.querySelectorAll('h1,h2,h3,h4,h5,h6').cl_map(headingElt => ({ title: headingElt.textContent,