Skip to content

Commit

Permalink
Supports configuring the theme of the Markdown editor.
Browse files Browse the repository at this point in the history
  • Loading branch information
cweijan committed Mar 4, 2024
1 parent 50224ac commit 8e4bd73
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
1 change: 0 additions & 1 deletion README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
编辑器使用说明: [禁用方式看这里](https://github.com/cweijan/vscode-office?tab=readme-ov-file#markdown)

- 编辑方式: 直接通过vscode打开md文件.
- 配置 `vscode-office.autoTheme": false`可将编辑器设置为亮白色.
- 点击以下按钮可打开VSCode内置编辑器.
![img](image/README-CN/1640579182342.png)
- 在编辑器打开右键菜单可将markdown导出为pdf, docx或者html, pdf依赖于chromium, 可通过 `vscode-office.chromiumPath`配置chromium浏览器路径.
Expand Down
1 change: 0 additions & 1 deletion README-TW.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
編輯器使用說明: [禁用方式看這裡](https://github.com/cweijan/vscode-office?tab=readme-ov-file#markdown)

* 編輯方式:直接透過 VS Code 開啟 `md` 檔案
* 配置 `vscode-office.autoTheme": false` 可將編輯器設定為亮白色
* 點選以下按鈕可開啟 VSCode 內建編輯器
![img](image/README-CN/1640579182342.png)
* 在編輯器開啟右鍵選單可將 Markdown 匯出為 PDF、DOCX 或者 HTML、PDF 依賴於 Chromium,可透過 `vscode-office.chromiumPath` 配置 Chromium 瀏覽器路徑
Expand Down
15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,16 @@
"default": true,
"description": "Preview code in markdown."
},
"vscode-office.editorTheme": {
"type": "string",
"enum": [
"light",
"auto",
"solarized"
],
"default": "light",
"markdownDescription": "The theme for the Markdown editor."
},
"vscode-office.previewCodeHighlight.style": {
"type": "string",
"enum": [
Expand Down Expand Up @@ -507,11 +517,6 @@
"default": true,
"markdownDescription": "Show line numbers in markdown preview code window. Only applies when `#vscode-office.previewCode#` is enabled."
},
"vscode-office.autoTheme": {
"type": "boolean",
"default": true,
"description": "Viewer follow vscode theme."
},
"vscode-office.editorLanguage": {
"type": "string",
"enum": [
Expand Down
9 changes: 5 additions & 4 deletions resource/vditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ loadConfigs()

handler.on("open", async (md) => {
const { config, language } = md;
if (config.autoTheme) {
addAutoTheme(md.rootPath)
}
addAutoTheme(md.rootPath, config.editorTheme)
const editor = new Vditor('vditor', {
value: md.content,
_lutePath: md.rootPath + '/lute.min.js',
Expand Down Expand Up @@ -91,9 +89,12 @@ handler.on("open", async (md) => {
}).emit("init")


function addAutoTheme(rootPath) {
function addAutoTheme(rootPath, theme) {
if (theme == 'light') return;
importCSS(rootPath, 'base.css')
importCSS(rootPath, 'theme/auto.css')
if (theme == 'auto') return;
importCSS(rootPath, `theme/${theme}.css`)
}

function importCSS(rootPath, path) {
Expand Down
1 change: 0 additions & 1 deletion src/provider/officeViewerProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ export class OfficeViewerProvider implements vscode.CustomReadonlyEditorProvider

if (htmlPath != null) {
webview.html = Util.buildPath(readFileSync(this.extensionPath + "/resource/" + htmlPath, 'utf8'), webview, this.extensionPath + "/resource")
.replace("$autoTheme", `${Global.getConfig('autoTheme')}`)
}

}
Expand Down

0 comments on commit 8e4bd73

Please sign in to comment.