網站首頁 編程語言 正文
概述
在使用Typora寫比較長的文章時,需要給章節編號,方便區分層次。如果手動編號,一旦章節順序改變,很多章節的編號都需要一一手動修改,極其麻煩。
Typora官方提供了自動編號的方法:https://support.typora.io/Auto-Numbering/。本文將對官方提供的方法,以及簡單改進進行介紹。
原理
這個方法的原理是,Typora基于瀏覽器開發(使用快捷鍵Shift+F12可以打開開發者工具)。因此,可以利用CSS實現自動編號。
具體操作
- 打開Typora -> 文件 -> 偏好設置 -> 外觀 -> 打開主題文件夾。
- 在主題文件夾下新建文件
base.user.css
。 - 將https://support.typora.io/Auto-Numbering/中提供的三份代碼(分別實現文章內容自動編號、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
相關推薦
- 2022-01-27 laravel的服務注入新增service層,多方式
- 2022-05-23 Python學習之sys模塊使用教程詳解_python
- 2023-05-15 sql語句中臨時表使用實例詳解_MsSql
- 2023-01-12 使用scipy.optimize的fsolve,root函數求解非線性方程問題_python
- 2022-10-11 在NVIDIA Jetson Xavier NX上使用tensorflow-gpu
- 2022-07-18 數據結構 III 深入理解棧和隊列實現
- 2022-12-12 C++?Boost?Phoenix庫示例分析使用_C 語言
- 2023-04-09 C語言中的分支循環其嵌套語句_C 語言
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支