1+ import type { ThemeName } from '@md/shared'
12import { initRenderer } from '@md/core/renderer'
2- import { customCssWithTemplate , customizeTheme , modifyHtmlContent } from '@md/core/utils'
3- import { css2json , themeMap } from '@md/shared'
3+ import { generateCSSVariables , modifyHtmlContent } from '@md/core/utils'
4+ import { baseCSSContent , themeMap } from '@md/shared'
45import * as vscode from 'vscode'
56import { css } from './css'
67import { MarkdownTreeDataProvider } from './treeDataProvider'
@@ -17,7 +18,7 @@ export function activate(context: vscode.ExtensionContext) {
1718 vscode . commands . registerCommand ( `markdown.setFontSize` , ( size : string ) => {
1819 treeDataProvider . updateFontSize ( size )
1920 } ) ,
20- vscode . commands . registerCommand ( `markdown.setTheme` , ( theme : keyof typeof themeMap ) => {
21+ vscode . commands . registerCommand ( `markdown.setTheme` , ( theme : ThemeName ) => {
2122 treeDataProvider . updateTheme ( theme )
2223 } ) ,
2324 vscode . commands . registerCommand ( `markdown.setPrimaryColor` , ( color : string ) => {
@@ -67,27 +68,30 @@ export function activate(context: vscode.ExtensionContext) {
6768 function updateWebview ( ) {
6869 if ( ! editor )
6970 return
71+
72+ // 使用新主题系统
7073 const renderer = initRenderer ( {
71- theme : customCssWithTemplate (
72- // TODO
73- css2json ( `` ) ,
74- treeDataProvider . getCurrentPrimaryColor ( ) ,
75- customizeTheme ( themeMap [ treeDataProvider . getCurrentTheme ( ) ] , {
76- fontSize : treeDataProvider . getCurrentFontSizeNumber ( ) ,
77- color : treeDataProvider . getCurrentPrimaryColor ( ) ,
78- } ) ,
79- ) ,
80- fonts : treeDataProvider . getCurrentFontFamily ( ) ,
81- size : treeDataProvider . getCurrentFontSize ( ) ,
82- isUseIndent : false ,
83- isUseJustify : false ,
8474 countStatus : treeDataProvider . getCurrentCountStatus ( ) ,
8575 isMacCodeBlock : treeDataProvider . getCurrentMacCodeBlock ( ) ,
8676 legend : `none` ,
8777 } )
78+
8879 const markdownContent = editor . document . getText ( )
8980 const html = modifyHtmlContent ( markdownContent , renderer )
90- panel . webview . html = wrapHtmlTag ( html , css )
81+
82+ // 生成主题 CSS
83+ const variables = generateCSSVariables ( {
84+ primaryColor : treeDataProvider . getCurrentPrimaryColor ( ) ,
85+ fontFamily : treeDataProvider . getCurrentFontFamily ( ) ,
86+ fontSize : treeDataProvider . getCurrentFontSize ( ) ,
87+ isUseIndent : false ,
88+ isUseJustify : false ,
89+ } )
90+
91+ const themeCSS = themeMap [ treeDataProvider . getCurrentTheme ( ) as ThemeName ]
92+ const completeCss = `${ variables } \n\n${ baseCSSContent } \n\n${ themeCSS } \n\n${ css } `
93+
94+ panel . webview . html = wrapHtmlTag ( html , completeCss )
9195 }
9296
9397 // render first webview
0 commit comments