Typora自動編號的具體操作
概述
在使用Typora寫比較長的文章時,需要給章節(jié)編號,方便區(qū)分層次。如果手動編號,一旦章節(jié)順序改變,很多章節(jié)的編號都需要一一手動修改,極其麻煩。
Typora官方提供了自動編號的方法:https://support.typora.io/Auto-Numbering/。本文將對官方提供的方法,以及簡單改進(jìn)進(jìn)行介紹。
原理
這個方法的原理是,Typora基于瀏覽器開發(fā)(使用快捷鍵Shift+F12可以打開開發(fā)者工具)。因此,可以利用CSS實現(xiàn)自動編號。
具體操作
- 打開Typora -> 文件 -> 偏好設(shè)置 -> 外觀 -> 打開主題文件夾。
- 在主題文件夾下新建文件
base.user.css。 - 將https://support.typora.io/Auto-Numbering/中提供的三份代碼(分別實現(xiàn)文章內(nèi)容自動編號、TOC自動編號、側(cè)邊欄大綱自動編號)復(fù)制到
base.user.css中。 - 重啟Typora。
改進(jìn)
官方提供的代碼會對一級標(biāo)題進(jìn)行編號,但實際寫文章時,一級標(biāo)題往往是文章標(biāo)題,無需編號,因此,我對代碼進(jìn)行了簡單修改。下面是修改后的代碼:
文章內(nèi)容自動編號:
/** initialize css counter */
h1 {
counter-reset: h2
}
h2 {
counter-reset: h3
}
h3 {
counter-reset: h4
}
h4 {
counter-reset: h5
}
h5 {
counter-reset: h6
}
/** put counter result into headings */
#write h2:before {
counter-increment: h2;
content: counter(h2) ". "
}
#write h3:before,
h3.md-focus.md-heading:before /** override the default style for focused headings */ {
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(h2) "." counter(h3) "." counter(h4) "." counter(h5) ". "
}
#write h6:before,
h6.md-focus.md-heading:before {
counter-increment: h6;
content: counter(h2) "." counter(h3) "." counter(h4) "." counter(h5) "." counter(h6) ". "
}
/** override the default style for focused headings */
#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;
}
TOC自動編號:
/* No link underlines in TOC */
.md-toc-inner {
text-decoration: none;
}
.md-toc-h1 {
margin-left: 0;
font-size: 1.5rem;
counter-reset: h2toc
}
.md-toc-h2 {
font-size: 1.1rem;
margin-left: 2rem;
counter-reset: h3toc
}
.md-toc-h3 {
margin-left: 3rem;
font-size: .9rem;
counter-reset: h4toc
}
.md-toc-h4 {
margin-left: 4rem;
font-size: .85rem;
counter-reset: h5toc
}
.md-toc-h5 {
margin-left: 5rem;
font-size: .8rem;
counter-reset: h6toc
}
.md-toc-h6 {
margin-left: 6rem;
font-size: .75rem;
}
.md-toc-h2:before {
color: black;
counter-increment: h2toc;
content: counter(h2toc) ". "
}
.md-toc-h2 .md-toc-inner {
margin-left: 0;
}
.md-toc-h3:before {
color: black;
counter-increment: h3toc;
content: counter(h2toc) ". " counter(h3toc) ". "
}
.md-toc-h3 .md-toc-inner {
margin-left: 0;
}
.md-toc-h4:before {
color: black;
counter-increment: h4toc;
content: counter(h2toc) ". " counter(h3toc) ". " counter(h4toc) ". "
}
.md-toc-h4 .md-toc-inner {
margin-left: 0;
}
.md-toc-h5:before {
color: black;
counter-increment: h5toc;
content: counter(h2toc) ". " counter(h3toc) ". " counter(h4toc) ". " counter(h5toc) ". "
}
.md-toc-h5 .md-toc-inner {
margin-left: 0;
}
.md-toc-h6:before {
color: black;
counter-increment: h6toc;
content: counter(h2toc) ". " counter(h3toc) ". " counter(h4toc) ". " counter(h5toc) ". " counter(h6toc) ". "
}
.md-toc-h6 .md-toc-inner {
margin-left: 0;
}
側(cè)邊欄大綱自動編號:
.outline-h1 {
counter-reset: h2
}
.outline-h2 {
counter-reset: h3
}
.outline-h3 {
counter-reset: h4
}
.outline-h4 {
counter-reset: h5
}
.outline-h5 {
counter-reset: h6
}
.outline-h2>.outline-item>.outline-label:before {
counter-increment: h2;
content: counter(h2) ". "
}
.outline-h3>.outline-item>.outline-label:before {
counter-increment: h3;
content: counter(h2) "." counter(h3) ". "
}
.outline-h4>.outline-item>.outline-label:before {
counter-increment: h4;
content: counter(h2) "." counter(h3) "." counter(h4) ". "
}
.outline-h5>.outline-item>.outline-label:before {
counter-increment: h5;
content: counter(h2) "." counter(h3) "." counter(h4) "." counter(h5) ". "
}
.outline-h6>.outline-item>.outline-label:before {
counter-increment: h6;
content: counter(h2) "." counter(h3) "." counter(h4) "." counter(h5) "." counter(h6) ". "
}
效果圖

到此這篇關(guān)于Typora自動編號的文章就介紹到這了,更多相關(guān)Typora自動編號內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
最新IntelliJ IDEA 2020.2永久激活碼(親測有效)
今天一大波朋友反饋idea2020激活碼失效的問題,小編快馬加鞭給大家找到解決方案,本文以IDEA 2020.2.4激活碼破解教程為例給大家詳細(xì)介紹,需要idea2020激活碼的朋友快來參考下本文吧2020-11-11
高性能高可用高并發(fā)架構(gòu)和系統(tǒng)設(shè)計思路大綱
高性能架構(gòu)和系統(tǒng)設(shè)計要求高并發(fā)高性能,高性能更多的是先從編碼角度、架構(gòu)使用角度去讓我們的單機(jī)(單實例)有更好的性能,然后再從整個系統(tǒng)層面來擁有更好的性能;高并發(fā)則直接是全局角度來讓我們的系統(tǒng)在全鏈路下都能夠抗住更多的并發(fā)請求2023-08-08
VSCode各語言運(yùn)行環(huán)境配置方法示例詳解
這篇文章主要介紹了VSCode各語言運(yùn)行環(huán)境配置方法,本文通過實例代碼給大家介紹的非常詳細(xì),對大家介紹的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-05-05
resty更新header控制api版本數(shù)據(jù)源讀寫分離
這篇文章主要介紹了resty的1.2.0-SNAPSHOT版本更新,可以通過header控制api的版本實現(xiàn)數(shù)據(jù)源讀寫分離,有需要的朋友可以借鑒參考下,希望能夠有所幫助<BR>,2022-03-03

