• Typora设置标题自动标号


    Typora由于默认标题无法自动标号,每次编辑时需要手动处理。为实现标题自动编号,需要进行相关操作。

    一 官方说明

    在这里插入图片描述

    To achieve this, add the following to your base.user.css or [theme].user.css in the theme folder.

    1. /** initialize css counter */
    2. #write {
    3. counter-reset: h1
    4. }
    5. h1 {
    6. counter-reset: h2
    7. }
    8. h2 {
    9. counter-reset: h3
    10. }
    11. h3 {
    12. counter-reset: h4
    13. }
    14. h4 {
    15. counter-reset: h5
    16. }
    17. h5 {
    18. counter-reset: h6
    19. }
    20. /** put counter result into headings */
    21. #write h1:before {
    22. counter-increment: h1;
    23. content: counter(h1) ". "
    24. }
    25. #write h2:before {
    26. counter-increment: h2;
    27. content: counter(h1) "." counter(h2) ". "
    28. }
    29. #write h3:before,
    30. h3.md-focus.md-heading:before /** override the default style for focused headings */ {
    31. counter-increment: h3;
    32. content: counter(h1) "." counter(h2) "." counter(h3) ". "
    33. }
    34. #write h4:before,
    35. h4.md-focus.md-heading:before {
    36. counter-increment: h4;
    37. content: counter(h1) "." counter(h2) "." counter(h3) "." counter(h4) ". "
    38. }
    39. #write h5:before,
    40. h5.md-focus.md-heading:before {
    41. counter-increment: h5;
    42. content: counter(h1) "." counter(h2) "." counter(h3) "." counter(h4) "." counter(h5) ". "
    43. }
    44. #write h6:before,
    45. h6.md-focus.md-heading:before {
    46. counter-increment: h6;
    47. content: counter(h1) "." counter(h2) "." counter(h3) "." counter(h4) "." counter(h5) "." counter(h6) ". "
    48. }
    49. /** override the default style for focused headings */
    50. #write>h3.md-focus:before,
    51. #write>h4.md-focus:before,
    52. #write>h5.md-focus:before,
    53. #write>h6.md-focus:before,
    54. h3.md-focus:before,
    55. h4.md-focus:before,
    56. h5.md-focus:before,
    57. h6.md-focus:before {
    58. color: inherit;
    59. border: inherit;
    60. border-radius: inherit;
    61. position: inherit;
    62. left:initial;
    63. float: none;
    64. top:initial;
    65. font-size: inherit;
    66. padding-left: inherit;
    67. padding-right: inherit;
    68. vertical-align: inherit;
    69. font-weight: inherit;
    70. line-height: inherit;
    71. }

    4.1、Auto-Numbering in TOC
    If you want TOC entities to be displayed auto-numbered, you could try http://pastebin.com/NYugSbXk posted by a Typora user.
     

    1. /**************************************
    2. * Header Counters in TOC
    3. **************************************/
    4. /* No link underlines in TOC */
    5. .md-toc-inner {
    6. text-decoration: none;
    7. }
    8. .md-toc-content {
    9. counter-reset: h1toc
    10. }
    11. .md-toc-h1 {
    12. margin-left: 0;
    13. font-size: 1.5rem;
    14. counter-reset: h2toc
    15. }
    16. .md-toc-h2 {
    17. font-size: 1.1rem;
    18. margin-left: 2rem;
    19. counter-reset: h3toc
    20. }
    21. .md-toc-h3 {
    22. margin-left: 3rem;
    23. font-size: .9rem;
    24. counter-reset: h4toc
    25. }
    26. .md-toc-h4 {
    27. margin-left: 4rem;
    28. font-size: .85rem;
    29. counter-reset: h5toc
    30. }
    31. .md-toc-h5 {
    32. margin-left: 5rem;
    33. font-size: .8rem;
    34. counter-reset: h6toc
    35. }
    36. .md-toc-h6 {
    37. margin-left: 6rem;
    38. font-size: .75rem;
    39. }
    40. .md-toc-h1:before {
    41. color: black;
    42. counter-increment: h1toc;
    43. content: counter(h1toc) ". "
    44. }
    45. .md-toc-h1 .md-toc-inner {
    46. margin-left: 0;
    47. }
    48. .md-toc-h2:before {
    49. color: black;
    50. counter-increment: h2toc;
    51. content: counter(h1toc) ". " counter(h2toc) ". "
    52. }
    53. .md-toc-h2 .md-toc-inner {
    54. margin-left: 0;
    55. }
    56. .md-toc-h3:before {
    57. color: black;
    58. counter-increment: h3toc;
    59. content: counter(h1toc) ". " counter(h2toc) ". " counter(h3toc) ". "
    60. }
    61. .md-toc-h3 .md-toc-inner {
    62. margin-left: 0;
    63. }
    64. .md-toc-h4:before {
    65. color: black;
    66. counter-increment: h4toc;
    67. content: counter(h1toc) ". " counter(h2toc) ". " counter(h3toc) ". " counter(h4toc) ". "
    68. }
    69. .md-toc-h4 .md-toc-inner {
    70. margin-left: 0;
    71. }
    72. .md-toc-h5:before {
    73. color: black;
    74. counter-increment: h5toc;
    75. content: counter(h1toc) ". " counter(h2toc) ". " counter(h3toc) ". " counter(h4toc) ". " counter(h5toc) ". "
    76. }
    77. .md-toc-h5 .md-toc-inner {
    78. margin-left: 0;
    79. }
    80. .md-toc-h6:before {
    81. color: black;
    82. counter-increment: h6toc;
    83. content: counter(h1toc) ". " counter(h2toc) ". " counter(h3toc) ". " counter(h4toc) ". " counter(h5toc) ". " counter(h6toc) ". "
    84. }
    85. .md-toc-h6 .md-toc-inner {
    86. margin-left: 0;
    87. }
    88. /**************************************
    89. * Header Counters in Content
    90. **************************************/
    91. /** initialize css counter */
    92. #write {
    93. counter-reset: h1
    94. }
    95. h1 {
    96. counter-reset: h2
    97. }
    98. h2 {
    99. counter-reset: h3
    100. }
    101. h3 {
    102. counter-reset: h4
    103. }
    104. h4 {
    105. counter-reset: h5
    106. }
    107. h5 {
    108. counter-reset: h6
    109. }
    110. /** put counter result into headings */
    111. #write h1:before {
    112. counter-increment: h1;
    113. content: counter(h1) ". "
    114. }
    115. #write h2:before {
    116. counter-increment: h2;
    117. content: counter(h1) "." counter(h2) ". "
    118. }
    119. #write h3:before, h3.md-focus.md-heading:before { /*override the default style for focused headings */
    120. counter-increment: h3;
    121. content: counter(h1) "." counter(h2) "." counter(h3) ". "
    122. }
    123. #write h4:before, h4.md-focus.md-heading:before {
    124. counter-increment: h4;
    125. content: counter(h1) "." counter(h2) "." counter(h3) "." counter(h4) ". "
    126. }
    127. #write h5:before, h5.md-focus.md-heading:before {
    128. counter-increment: h5;
    129. content: counter(h1) "." counter(h2) "." counter(h3) "." counter(h4) "." counter(h5) ". "
    130. }
    131. #write h6:before, h6.md-focus.md-heading:before {
    132. counter-increment: h6;
    133. content: counter(h1) "." counter(h2) "." counter(h3) "." counter(h4) "." counter(h5) "." counter(h6) ". "
    134. }
    135. /** override the default style for focused headings */
    136. #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 {
    137. color: inherit;
    138. border: inherit;
    139. border-radius: inherit;
    140. position: inherit;
    141. left: initial;
    142. float: none;
    143. top: initial;
    144. font-size: inherit;
    145. padding-left: inherit;
    146. padding-right: inherit;
    147. vertical-align: inherit;
    148. font-weight: inherit;
    149. line-height: inherit;
    150. }

    4.2、Auto-Numbering Outline panel
    To show auto-numbering in Typora’s Outline panel, disable the collapsable outline panel in the preferences panel and then try https://pastebin.com/XmYgBbaz.
     

    1. .sidebar-content {
    2. counter-reset: h1
    3. }
    4. .outline-h1 {
    5. counter-reset: h2
    6. }
    7. .outline-h2 {
    8. counter-reset: h3
    9. }
    10. .outline-h3 {
    11. counter-reset: h4
    12. }
    13. .outline-h4 {
    14. counter-reset: h5
    15. }
    16. .outline-h5 {
    17. counter-reset: h6
    18. }
    19. .outline-h1>.outline-item>.outline-label:before {
    20. counter-increment: h1;
    21. content: counter(h1) ". "
    22. }
    23. .outline-h2>.outline-item>.outline-label:before {
    24. counter-increment: h2;
    25. content: counter(h1) "." counter(h2) ". "
    26. }
    27. .outline-h3>.outline-item>.outline-label:before {
    28. counter-increment: h3;
    29. content: counter(h1) "." counter(h2) "." counter(h3) ". "
    30. }
    31. .outline-h4>.outline-item>.outline-label:before {
    32. counter-increment: h4;
    33. content: counter(h1) "." counter(h2) "." counter(h3) "." counter(h4) ". "
    34. }
    35. .outline-h5>.outline-item>.outline-label:before {
    36. counter-increment: h5;
    37. content: counter(h1) "." counter(h2) "." counter(h3) "." counter(h4) "." counter(h5) ". "
    38. }
    39. .outline-h6>.outline-item>.outline-label:before {
    40. counter-increment: h6;
    41. content: counter(h1) "." counter(h2) "." counter(h3) "." counter(h4) "." counter(h5) "." counter(h6) ". "
    42. }

    二 具体操作

    1 打开主题文件夹

    打开typora,先点击“文件”,再点击“偏好设置”,再点击“外观”,最后点击“打开主题文件”来到如下界面。

     

     2 修改主题文件

    • 在此路径下新建“base.user.css”,将上面三份代码复制到到文档里面,保存后退出。

    3 重启Typora

    三 注意

    1. 开始编号标题必须是一级标题格式。否则编号出错

    2. 有几个数字代表几级标题。如1.代表一级标题。1.1.1代表三级标题

    3. 设置为标题格式后输入内容即可对标题编辑

    参考链接

    1. typora设置标题自动编号_落花逐流水的博客-CSDN博客_typora标题自动编号

    2. 设置typora标题、目录、大纲自动编号_MTpanda酉生的博客-CSDN博客_typora标题自动编号

  • 相关阅读:
    一无所有刷题记♥
    MySQL笔记——索引
    地平线 自动化测试|测试开发 面试真题|面经 汇总
    STM32驱动4寸ST7796S LCD-TFT屏
    动态规划题: 统计每个月兔子的总数
    AxureR9根据选择内容触发不同的事件
    Python和Java应该如何选择?该怎么学?
    46_StringBuilder类
    IPKISS Tutorials 3------绘制矩形版图
    app小程序手机端Python爬虫实战04-u2自动化工具基本操作-操作设备
  • 原文地址:https://blog.csdn.net/m0_49448331/article/details/126074664