VScode 修改 Markdown Preview Enhanced 字体以及大纲编号

修改字体和背景颜色

  1. 按快捷键 Ctrl + , 打开设置,搜索 markdown-preview-enhanced.previewTheme,选择一个黑色主题的css,如 github-dark.css.

修改自动编号和背景颜色

背景颜色

按 F1 或者 Ctrl + Shift + P,输入 Customize CSS,选择 Markdown Preview Enhanced 对应的css (建议全局)

css 复制代码
.markdown-preview.markdown-preview {
  // modify your style here
  // eg: background-color: blue;
  background-color: #000;
  font-family: 'Consolas'; // 字体类型
  font-size: 16px;  	   // 字体大小
}

目录自动编号

在刚才打开的style.less 文件中输入以下样式,注意样式不要放在.markdown-preview.markdown-preview 中

css 复制代码
/**
 * 首先在父元素中(在这里是 body 元素),初始化你想要编号的最大标题的计数。
 */
 body {
  counter-reset: hbody;
}
  
/**
 * 然后父标题初始化子标题的计数,下面以此类推。
 */
h1 {
  counter-reset: h1;
}

h2 {
  counter-reset: h2;
}

h3 {
  counter-reset: h3;
}

h4 {
  counter-reset: h4;
}

h5 {
  counter-reset: h5;
}

  
/**
 * 接着在每个标题前面自动加上编号
 *
 * 如果不想从 h1 开始自动编号,而是把 h1 当成文章题目,从 h2 开始自动编号,那么
 * 1. 把 h1:before 注释
 * 2. 从 h2:before 开始到 h6:before,把编号开头的 counter(hbody) "." 这一部分删除
 */
// h1:before {
//   counter-increment: hbody;
//   content: counter(hbody) ". ";
// }
h2:before {
  counter-increment: h1;
  content:counter(h1) ". ";
}

h3:before {
  counter-increment: h2;
  content:counter(h1) "." counter(h2) ". ";
}

h4:before {
  counter-increment: h3;
  content:counter(h1) "." counter(h2) "." counter(h3) ". ";
}

h5:before {
  counter-increment: h4;
  content:counter(h1) "." counter(h2) "." counter(h3) "." counter(h4) ". ";
}

h6:before {
  counter-increment: h5;
  content:counter(h1) "." counter(h2) "." counter(h3) "." counter(h4) "." counter(h5) ". ";
}
相关推荐
BD_Marathon3 天前
安装Jupyter notebook
ide·python·jupyter
讓丄帝愛伱4 天前
Zed Markdown 预览不能铺满全屏的原因及解决
ide
FungLeo4 天前
FengCMS · PHP+MySQL 升级实录 · 编辑器迁移:KindEditor → wangEditor5 +服务端 HTML Purifier
mysql·编辑器·php·富文本编辑器·fengcms
BD_Marathon5 天前
Jupyter魔法命令
ide·python·jupyter
郝学胜-神的一滴5 天前
Effective STL 条款 07:指针容器销毁前先删除
开发语言·c++·vscode·leetcode·rpc·visual studio
aaaameliaaa5 天前
VSCode的安装与配置
ide·笔记·vscode·编辑器
Star(up up up)7 天前
MySQL 事务隔离级别是如何实现的?从 MVCC 到锁机制原理详解
笔记·vscode·sql·学习·程序人生·mysql·学习方法
ScilogyHunter7 天前
[14] TMS570LC4357_VIM向量中断:128 通道、双 VIM 与硬件向量分发
单片机·编辑器·vim·excel·hercules·tms570
宝桥南山8 天前
Visual Studio 2026新特性 - 可以直接连接DeepSeek(使用Custom Endpoint Provider配置项)
ide·microsoft·微软·aigc·.net·visual studio
wangqiaowq9 天前
Protégé 开源本体(Ontology)编辑器
编辑器