叶子的自定义标题ID。
foliantcontrib.customids的Python项目详细描述
自定义项
custom ids是一个预处理器,它允许在使用mkdocs或另一个提供html输出的后端构建的项目中使用pandoc样式语法,为标记源中的标题定义自定义标识符(id)。这些id可用于指向页面特定部分的超链接。
安装
$ pip install foliantcontrib.customids
用法
要启用预处理器,请将customids
添加到项目配置中的preprocessors
部分:
preprocessors:-customids
预处理器支持以下选项:
-customids:stylesheet_path:!pathcustomids.csstargets:-pre-mkdocs-site-ghp
stylesheet_path
:css样式表文件的路径。此样式表应定义.custom_id_anchor_container
、.custom_id_anchor_container_level_N
、.custom_id_anchor
和.custom_id_anchor_level_N
类的规则。这里的N
是标题级别(1
到6
)。默认路径是customids.css
。如果样式表文件不存在,将使用默认内置样式表。
targets
:预处理器允许的目标。如果未指定(默认情况下),预处理器将应用于所有目标。
可以在同一行的标题内容之后指定自定义ID标记语法示例:
# First Heading {#custom_id_for_first_heading} A paragraph. ## Second Heading {#custom_id_for_second_heading} Some another paragraph.
此标记源代码最终将转换为HTML代码:
<divclass="custom_id_anchor_container custom_id_anchor_container_level_1"><divid="custom_id_for_first_heading"class="custom_id_anchor custom_id_anchor_level_1"></div></div><h1>First Heading</h1><p>A paragraph.</p><divclass="custom_id_anchor_container custom_id_anchor_container_level_2"><divid="custom_id_for_second_heading"class="custom_id_anchor custom_id_anchor_level_2"></div></div><h2>Second Heading</h2><p>Some another paragraph.</p>
(请注意,customids预处理器不会将标记语法转换为html;它只将html标记<div class="custom_id_anchor_container">...</div>
插入标记代码。)
自定义标识不能包含空格和非ascii字符。
引用自定义ID的超链接示例:
[Link to Heading 1](#custom_id_for_first_heading) [Link to Heading 2 in some document at the current site](/some/page/#custom_id_for_second_heading) [Link to some heading with custom ID at an external site](https://some.site/path/to/the/page/#some_custom_id)