3.2.4 添加锚点
This commit is contained in:
parent
d6f061c434
commit
2824832906
@ -29,6 +29,7 @@ from pymdownx.smartsymbols import SmartSymbolsExtension
|
||||
from pymdownx.superfences import fence_div_format
|
||||
from pymdownx.tasklist import TasklistExtension
|
||||
from pymdownx.tilde import DeleteSubExtension
|
||||
from pymdownx.magiclink import MagiclinkExtension
|
||||
|
||||
from .Define import Variable
|
||||
|
||||
@ -173,7 +174,10 @@ class Syllabus(BlockProcessor):
|
||||
return False
|
||||
|
||||
|
||||
class _Anchor(InlineProcessor):
|
||||
class Anchor(InlineProcessor):
|
||||
"""
|
||||
{#定义锚点}
|
||||
"""
|
||||
def handleMatch(self, m: Match[str], data: str) -> (Tuple[xml.etree.ElementTree.Element, int, int] |
|
||||
Tuple[None, None, None]):
|
||||
"""
|
||||
@ -190,6 +194,9 @@ class _Anchor(InlineProcessor):
|
||||
|
||||
|
||||
class LinkLine(InlineProcessor):
|
||||
"""
|
||||
{行内链接}
|
||||
"""
|
||||
def handleMatch(self, m: Match[str], data: str) -> (Tuple[xml.etree.ElementTree.Element, int, int] |
|
||||
Tuple[None, None, None]):
|
||||
"""
|
||||
@ -225,7 +232,7 @@ class Pre(Extension):
|
||||
md.preprocessors.register(PreProcess(self.variable), 'pre_process', 1000)
|
||||
|
||||
|
||||
class Basic(Extension):
|
||||
class BasicExtension(Extension):
|
||||
"""
|
||||
渲染基本样式
|
||||
"""
|
||||
@ -245,36 +252,17 @@ class Basic(Extension):
|
||||
md.parser.blockprocessors.register(Syllabus(md.parser), 'syllabus', 182) # 渲染提纲
|
||||
|
||||
|
||||
class Anchor(Extension):
|
||||
class AnchorExtension(Extension):
|
||||
def extendMarkdown(self, md: Markdown):
|
||||
"""
|
||||
添加扩展
|
||||
:param md: 转换器
|
||||
"""
|
||||
md.registerExtension(self) # 注册扩展
|
||||
md.inlinePatterns.register(_Anchor(r'\{{#([^{}#]+)}}'), 'anchor', 0) # 定义锚点
|
||||
md.inlinePatterns.register(Anchor(r'\{{#([^{}#]+)}}'), 'anchor', 0) # 定义锚点
|
||||
md.inlinePatterns.register(LinkLine(r'\{{([^{}#]+)}}'), 'line_link', 0) # 添加页内链接
|
||||
|
||||
|
||||
class Code(Extension):
|
||||
def __init__(self, variable: Variable):
|
||||
"""
|
||||
初始化
|
||||
:param variable: 变量字典
|
||||
"""
|
||||
super().__init__()
|
||||
self.variable = variable
|
||||
|
||||
def extendMarkdown(self, md: Markdown):
|
||||
"""
|
||||
添加扩展
|
||||
:param md: 转换器
|
||||
"""
|
||||
md.registerExtension(self) # 注册扩展
|
||||
# md.treeprocessors.register(CodeLine(variable=self.variable), 'code_line', 0) # 渲染单行代码块
|
||||
# md.treeprocessors.register(CodeBlock(), 'code_block', 1000) # 渲染多行代码块
|
||||
|
||||
|
||||
Extensions = {
|
||||
# 自带
|
||||
'元数据': meta.MetaExtension(),
|
||||
@ -313,9 +301,11 @@ Extensions = {
|
||||
'上标': InsertSupExtension(),
|
||||
'高级列表': FancyListExtension(),
|
||||
'高级标题': SaneHeadersExtension(),
|
||||
'超级链接': MagiclinkExtension(),
|
||||
|
||||
# 自定义
|
||||
'基本风格': Basic(),
|
||||
'基本风格': BasicExtension(),
|
||||
'锚点': AnchorExtension(),
|
||||
}
|
||||
|
||||
|
||||
|
10
README.html
10
README.html
@ -164,6 +164,8 @@
|
||||
<p><a href="链接地址">链接文本</a></p>
|
||||
<p><a href="https://crossdark.com">CrossDark</a></p>
|
||||
<p><a href="https://crossdark.net/">https://crossdark.net/</a></p>
|
||||
<p><a href="https://crossdark.net/">https://crossdark.net/</a></p>
|
||||
<p><a href="mailto:liuhanbo333@icloud.com">liuhanbo333@icloud.com</a></p>
|
||||
<h3 id="1.3.2">1.3.2 图片</h3>
|
||||
<p><img alt="链接图片" src="链接地址" /></p>
|
||||
<p><img alt="sea" src="https://crossdark.com/wp-content/uploads/2024/05/1715259682-sea.jpg" /></p>
|
||||
@ -175,9 +177,9 @@
|
||||
<p>直接在文本中使用 <abbr title="长的文本">缩写</abbr> 即可</p>
|
||||
<h1 id="3">3 锚点</h1>
|
||||
<h2 id="3.1">3.1 定义</h2>
|
||||
<p>{{#锚点名}}</p>
|
||||
<p><span id="锚点名">锚点名</span></p>
|
||||
<h2 id="3.2">3.2 页内链接</h2>
|
||||
<p>{{锚点名}}</p>
|
||||
<p><a href="#锚点名">锚点名</a></p>
|
||||
<h1 id="4">4 代码块</h1>
|
||||
<h2 id="4.1">4.1 <code>单行</code></h2>
|
||||
<p>Here is some code: <code class="highlight"><span class="kn">import</span> <span class="nn">pymdownx</span><span class="p">;</span> <span class="n">pymdownx</span><span class="o">.</span><span class="n">__version__</span></code>.</p>
|
||||
@ -304,7 +306,7 @@
|
||||
<p>7.1.3. 错误示范</p>
|
||||
<p>不能出现两个及以上连续的点,例如:</p>
|
||||
<p>7..1...4 错误示范</p>
|
||||
<p>提纲号会被自动配置为锚点,可直接使用{{7}}{{7.1}}</p>
|
||||
<p>提纲号会被自动配置为锚点,可直接使用<a href="#7">7</a><a href="#7.1">7.1</a></p>
|
||||
<h1 id="8">8 注释</h1>
|
||||
<!-- 这是注释 -->
|
||||
|
||||
@ -444,7 +446,7 @@
|
||||
<hr />
|
||||
<ol>
|
||||
<li id="fn:脚注">
|
||||
<p>一段长的文本用于说明 <a class="footnote-backref" href="#fnref:脚注" title="Jump back to footnote 1 in the text">link</a></p>
|
||||
<p>一段长的文本用于说明 <a class="footnote-backref" href="#fnref:脚注" title="Jump back to footnote 1 in the text">↩</a></p>
|
||||
</li>
|
||||
</ol>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user