当前位置: 首页 > 编程文章 >

Typora自动编号的具体操作

Typora自动编号的具体操作

作者:顾言时间:2025-04-06 14:24:05浏览:388

本文介绍在Typora中实现章节、目录及侧边栏大纲自动编号的方法。通过修改用户自定义CSS文件,利用浏览器内核的计数器功能,可避免手动调整编号的繁琐。同时提供针对一级标题无需编号场景的代码改进方案,确保排版整洁。

本文目录展开

概述

撰写长篇幅文档时,为章节添加层级编号有助于理清结构。若采用手动输入方式,一旦调整章节顺序,后续所有编号均需逐一修正,效率低下且易出错。

Typora官方提供了基于CSS的自动编号解决方案:https://support.typora.io/Auto-Numbering/。本文将详细阐述该官方方法,并分享针对特定需求的简易改进技巧。

原理

该功能的实现依赖于Typora基于Chromium内核开发的特性(可通过快捷键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) ". "
}

效果图

在这里插入图片描述

以上就是Typora自动编号功能的完整配置流程。如需了解更多相关技巧,欢迎查阅本站往期文章或持续关注后续更新,感谢您的支持!

上一篇
百万行WPF项目重构:架构、配置与性能优化实战

本文记录了一个百万行代码的WPF上位机项目历时一年半的重构过程。针对机型繁多导致的分支维护困难,采用面向接口编程实现业务逻辑通用化;通过集中化管理数据库配置及开发统一升级工具,解决打包繁琐问题;利用纯UI库剥离MVVM耦合;制定严格的代码行数限制与CodeReview机制提升质量;并通过懒加载策略将图片处理内存占用降低60%-70%。

下一篇
PHP array_keys 函数详解:获取数组键名

PHP中的array_keys函数用于从数组中提取并返回所有的键名,或仅返回匹配特定值的键名。该函数接受数组、可选的搜索值以及严格类型比较参数,能够灵活处理数字和字符串类型的索引,是进行数组数据检索和结构分析时的常用工具。

相关文章

更多
PHP实现新建文件自动编号的多种思路与代码示例

在PHP中实现新建文件时自动添加序号(如(2)、(3)),核心在于获取当前最大序号并递增。常见方法包括使用外部缓存文件记录数字,通过遍历目录结合正则表达式匹配现有文件名以找出最大值,以及利用while循环检测文件是否存在来生成唯一名称。不同方案在性能、智能性及代码复杂度上各有优劣,需根据具体场景选择。

2026.11.02 934
Typora 编辑器介绍与 v1.0.4 破解激活指南

Typora 是一款基于 GFM 标准的强大 Markdown 编辑器,以实时预览和无干扰界面著称。本文介绍了其核心功能如文件树管理和多格式导出,并详细记录了针对 Typora v1.0.4 版本的破解流程。通过安装 Python 和 Node.js 依赖,利用 typoraCracker 工具解包 app.asar 文件,替换 License.js 权限文件并重新打包,最终通过 keygen.js 生成有效序列号以解决激活弹窗问题。

2025.02.04 865
Typora 1.4.8 安装与破解激活指南

本文介绍 Typora 1.4.8 版本的安装及激活方法。该软件支持 macOS、Windows 及 Linux 系统,具备实时预览、多主题及数学公式等功能。由于百度网盘链接易被封禁,目前需通过微信公众号“Java技术迷”回复关键字“230223”获取破解补丁。安装时需将 winmm.dll 文件复制至软件目录以完成激活。

2025.04.24 826
2026年Typora破解与激活教程

本文介绍 Typora 在 2026 年的两种主要破解方式。第一种推荐适用于 Typora 1.3.8 版本,通过替换 winmm.dll 补丁实现永久激活;第二种适用于 1.2.4 版本,需修改 app.asar 文件并输入固定序列号。教程包含详细步骤、版本下载链接及注意事项,旨在帮助用户以非商用目的体验该 Markdown 编辑器。

2026.06.13 797
Typora 0.11.18 免费版本安装指南

Typora 于 2026 年 11 月 23 日发布 1.0 正式版并转为付费模式,0.11.18 成为最后一个免费版本。本文提供该版本的百度网盘永久链接及提取码,并详细演示从双击安装包到创建首个笔记的完整自定义安装流程,帮助用户在软件收费前完成本地部署。

2026.06.11 666
PHP实现的CSS更新类实例

本文分享一个由PHP实现的CSS更新类及其具体用法。该类文件名为CSSUpdate.class.php,配合demo示例程序展示了实际操作流程。完整源码可供下载参考,旨在帮助开发者在PHP程序设计中进行样式管理。

2025.05.11 558

专题推荐

更多
PHP 类与对象定义及继承

先看类声明、对象实例与属性访问。理解对象的创建和销毁后,再读继承、方法重载和关键字对照。已有代码遇到继承行为差异时,可进一步查看 final 方法与反射实例。

PHP 定时任务配置与运行

先确定任务运行间隔以及是否允许重叠。固定时间触发先看 Cron 案例,框架内和常驻服务再读对应示例。

Yii2 队列配置与常驻运行

先用一个最小任务跑通入队和消费,再检查 Web 与 Console 是否加载了相同的队列配置。确认命令能手动运行后再配置 Supervisor,最后验证进程重启时的处理情况。

PHP Session 过期时间设置方法

浏览器关闭、服务端回收和业务规定的闲置超时,可能在不同时间发生。对照配置项与应用层时间戳的做法,检查会话何时仍可读、何时应要求重新登录。

PHP URL 编码和解码方法

URL 路径片段和查询参数对空格的处理方式不同。先比较 urlencode 与 rawurlencode,再沿解码过程核对中文、加号和百分号,检查地址是否被重复编码或提前解码。

在线工具箱

更多
键码查询
键码查询

按下键盘按键时查看浏览器记录的键名和事件信息。

.env 配置检查
.env 配置检查

本地检查 .env 键值语法、引号、重复键及空值,预览解析结果,辅助排查 PHP 和 Laravel 环境配置。

进制转换
进制转换

转换二进制、十进制、十六进制等数值表示,辅助程序调试与进制学习。

HTML 标签安全清理
HTML 标签安全清理

清理 HTML 片段中的标签或危险内容,辅助整理待展示的文本。

文件 Base64 转换
文件 Base64 转换

把文件转为 Base64 文本,也可将编码内容还原为文件,方便接口传输与调试。