typora markdown 标题自动编号
1、参考资料
- https://blog.csdn.net/HackerTom/article/details/96640782
- https://zhuanlan.zhihu.com/p/110257979
2、具体操作步骤
![image-20200529100432557](https://i-blog.csdnimg.cn/blog_migrate/7c51ffd1f715a80d10f31de38b64b919.png)
- 文件夹目录为:C:\Users\Heygo\AppData\Roaming\Typora\themes,在该目录下添加一个名为 base.user.css 的 css 文件
![image-20200529100535802](https://i-blog.csdnimg.cn/blog_migrate/4a7250ac64725d644f75666b782805de.png)
#write {
counter-reset: h1
}
h1 {
counter-reset: h2
}
h2 {
counter-reset: h3
}
h3 {
counter-reset: h4
}
h4 {
counter-reset: h5
}
h5 {
counter-reset: h6
}
#write h1:before {
counter-increment: h1;
content: counter(h1) ". "
}
#write h2:before {
counter-increment: h2;
content: counter(h1) "." counter(h2) ". "
}
#write h3:before,
h3.md-focus.md-heading:before {
counter-increment: h3;
content: counter(h1) "." counter(h2) "." counter(h3) ". "
}
#write h4:before,
h4.md-focus.md-heading:before {
counter-increment: h4;
content: counter(h1) "." counter(h2) "." counter(h3) "." counter(h4) ". "
}
#write h5:before,
h5.md-focus.md-heading:before {
counter-increment: h5;
content: counter(h1) "." counter(h2) "." counter(h3) "." counter(h4) "." counter(h5) ". "
}
#write h6:before,
h6.md-focus.md-heading:before {
counter-increment: h6;
content: counter(h1) "." counter(h2) "." counter(h3) "." counter(h4) "." counter(h5) "." counter(h6) ". "
}
#write>h3.md-focus:before,
#write>h4.md-focus:before,
#write>h5.md-focus:before,
#write>h6.md-focus:before,
h3.md-focus:before,
h4.md-focus:before,
h5.md-focus:before,
h6.md-focus:before {
color: inherit;
border: inherit;
border-radius: inherit;
position: inherit;
left:initial;
float: none;
top:initial;
font-size: inherit;
padding-left: inherit;
padding-right: inherit;
vertical-align: inherit;
font-weight: inherit;
line-height: inherit;
}
![image-20200712182722498](https://i-blog.csdnimg.cn/blog_migrate/6acfbdd78c5cb618f42ab995614b067b.png)
3、我的自定义格式
3.1、样式一
#write {
counter-reset: h1
}
h1 {
counter-reset: h2
}
h2 {
counter-reset: h3
}
h3 {
counter-reset: h4
}
h4 {
counter-reset: h5
}
h5 {
counter-reset: h6
}
#write h1:before {
counter-increment: h1;
content: counter(h1) "、 "
}
#write h2:before {
counter-increment: h2;
content: counter(h1) "." counter(h2) "、 "
}
#write h3:before,
h3.md-focus.md-heading:before {
counter-increment: h3;
content: counter(h1) "." counter(h2) "." counter(h3) "、 "
}
#write h4:before,
h4.md-focus.md-heading:before {
counter-increment: h4;
content: counter(h4) "、"
}
#write h5:before,
h5.md-focus.md-heading:before {
counter-increment: h5;
content: counter(h5) ")、 "
}
#write h6:before,
h6.md-focus.md-heading:before {
counter-increment: h6;
content: "(" counter(h6) ")、"
}
#write>h3.md-focus:before,
#write>h4.md-focus:before,
#write>h5.md-focus:before,
#write>h6.md-focus:before,
h3.md-focus:before,
h4.md-focus:before,
h5.md-focus:before,
h6.md-focus:before {
color: inherit;
border: inherit;
border-radius: inherit;
position: inherit;
left:initial;
float: none;
top:initial;
font-size: inherit;
padding-left: inherit;
padding-right: inherit;
vertical-align: inherit;
font-weight: inherit;
line-height: inherit;
}
![image-20200711103543809](https://i-blog.csdnimg.cn/blog_migrate/3786ebcb4d143573a8b3975d64fa0b46.png)
3.2、样式二
- emmm… 上面的样式有一个缺点,一般我们都会使用一级标题作为文章的题目,这样后面的编号都是 1.x 、1.x.x 这样的格式,不太好看,我们再来改下吧
- base.user.css 中的代码
#write {
counter-reset: h2
}
h2 {
counter-reset: h3
}
h3 {
counter-reset: h4
}
h4 {
counter-reset: h5
}
h5 {
counter-reset: h6
}
#write h2:before {
counter-increment: h2;
content: counter(h2) "、 "
}
#write h3:before,
h3.md-focus.md-heading:before {
counter-increment: h3;
content: counter(h2) "." counter(h3) "、 "
}
#write h4:before,
h4.md-focus.md-heading:before {
counter-increment: h4;
content: counter(h2) "." counter(h3) "." counter(h4) "、"
}
#write h5:before,
h5.md-focus.md-heading:before {
counter-increment: h5;
content: counter(h5) "、 "
}
#write h6:before,
h6.md-focus.md-heading:before {
counter-increment: h6;
content: counter(h6) "、"
}
#write>h3.md-focus:before,
#write>h4.md-focus:before,
#write>h5.md-focus:before,
#write>h6.md-focus:before,
h3.md-focus:before,
h4.md-focus:before,
h5.md-focus:before,
h6.md-focus:before {
color: inherit;
border: inherit;
border-radius: inherit;
position: inherit;
left:initial;
float: none;
top:initial;
font-size: inherit;
padding-left: inherit;
padding-right: inherit;
vertical-align: inherit;
font-weight: inherit;
line-height: inherit;
}
![image-20200711103835493](https://i-blog.csdnimg.cn/blog_migrate/5cd052a5fb3b127486f1848718aa0707.png)