網(wǎng)站首頁 編程語言 正文
概述
在使用Typora寫比較長的文章時,需要給章節(jié)編號,方便區(qū)分層次。如果手動編號,一旦章節(jié)順序改變,很多章節(jié)的編號都需要一一手動修改,極其麻煩。
Typora官方提供了自動編號的方法:https://support.typora.io/Auto-Numbering/。本文將對官方提供的方法,以及簡單改進進行介紹。
原理
這個方法的原理是,Typora基于瀏覽器開發(fā)(使用快捷鍵Shift+F12可以打開開發(fā)者工具)。因此,可以利用CSS實現(xiàn)自動編號。
具體操作
- 打開Typora -> 文件 -> 偏好設置 -> 外觀 -> 打開主題文件夾。
- 在主題文件夾下新建文件
base.user.css
。 - 將https://support.typora.io/Auto-Numbering/中提供的三份代碼(分別實現(xiàn)文章內容自動編號、TOC自動編號、側邊欄大綱自動編號)復制到
base.user.css
中。 - 重啟Typora。
改進
官方提供的代碼會對一級標題進行編號,但實際寫文章時,一級標題往往是文章標題,無需編號,因此,我對代碼進行了簡單修改。下面是修改后的代碼:
文章內容自動編號:
/** 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; }
側邊欄大綱自動編號:
.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) ". " }
效果圖
原文鏈接:https://blog.csdn.net/xnightmare/article/details/119854519
相關推薦
- 2023-01-17 關于最大池化層和平均池化層圖解_python
- 2023-01-20 Python-with?open()?as?f的用法及說明_python
- 2022-01-05 npm ERR! code ENOENT npm ERR! syscall open npm ERR
- 2022-06-08 記錄一次奇怪的springboot cache redis緩存報錯解決
- 2022-03-14 npm run dev報錯如何解決,找了這么久也許這里有你想要的答案
- 2022-12-11 Dart多個future隊列完成加入順序關系及原子性論證_Dart
- 2022-05-06 React自定義Hook-useForkRef的具體使用_React
- 2022-09-04 Docker-Compose?容器集群的快速編排方法_docker
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學習環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結構-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支