From b885051c67f524dce4f76d9dab54cfb5182b7509 Mon Sep 17 00:00:00 2001 From: crossdark Date: Fri, 25 Oct 2024 20:09:49 +0800 Subject: [PATCH] =?UTF-8?q?3.1=20=E4=BD=BF=E7=94=A8pymdownx?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CrossDown/Core.py | 46 +++++++--- README.html | 208 ++++++++++++++++++++++++++++++---------------- README.md | 129 +++++++++++++++++++++------- 3 files changed, 273 insertions(+), 110 deletions(-) diff --git a/CrossDown/Core.py b/CrossDown/Core.py index a6ed85b..fa4ce36 100644 --- a/CrossDown/Core.py +++ b/CrossDown/Core.py @@ -1,5 +1,15 @@ from markdown.extensions import Extension, extra, admonition, meta, sane_lists, toc, wikilinks, codehilite, legacy_attrs + from pymdownx.arithmatex import ArithmatexExtension +from pymdownx.emoji import EmojiExtension +from pymdownx.blocks import BlocksExtension +from pymdownx.blocks.admonition import AdmonitionExtension +from pymdownx.blocks.definition import DefinitionExtension +from pymdownx.blocks.details import DetailsExtension +from pymdownx.blocks.html import HTMLExtension +from pymdownx.blocks.tab import TabExtension +from pymdownx.caret import CaretProcessor +from pymdownx.critic import CriticExtension from pygments.formatters import HtmlFormatter @@ -49,9 +59,9 @@ class HighlightHtmlFormatter(HtmlFormatter): Extensions = { # 自带 '基本扩展': extra.ExtraExtension(fenced_code={'lang_prefix': ''}), - '警告扩展': admonition.AdmonitionExtension(), + # '警告扩展': admonition.AdmonitionExtension(), '元数据': meta.MetaExtension(), - '能列表': sane_lists.SaneListExtension(), + # '能列表': sane_lists.SaneListExtension(), '目录': toc.TocExtension(), '内部链接': wikilinks.WikiLinkExtension(), # '代码高亮': codehilite.CodeHiliteExtension(guess_lang=False, pygments_formatter=HighlightHtmlFormatter), @@ -59,11 +69,20 @@ Extensions = { # pymdownx '超级数学': ArithmatexExtension(), + 'EMOJI': EmojiExtension(), + '块扩展': BlocksExtension(), + '警告': AdmonitionExtension(), + '定义列表': DefinitionExtension(), + '详情': DetailsExtension(), + 'HTML': HTMLExtension(), + '标签': TabExtension(), + '批评': CriticExtension(), } class PreProcess(Preprocessor): """预处理""" + def __init__(self, variable: Variable): super().__init__() self.variable = variable @@ -94,7 +113,8 @@ class Simple(InlineProcessor): super().__init__(pattern) self.tag = tag - def handleMatch(self, m: Match[str], data: str) -> Tuple[xml.etree.ElementTree.Element, int, int] | Tuple[None, None, None]: + def handleMatch(self, m: Match[str], data: str) -> Tuple[xml.etree.ElementTree.Element, int, int] | Tuple[ + None, None, None]: """ 处理匹配 :param m: re模块的匹配对象 @@ -123,7 +143,8 @@ class Nest(InlineProcessor): self.outer_tag = outer_tag self.inner_tag = inner_tag - def handleMatch(self, m: Match[str], data: str) -> Tuple[xml.etree.ElementTree.Element, int, int] | Tuple[None, None, None]: + def handleMatch(self, m: Match[str], data: str) -> Tuple[xml.etree.ElementTree.Element, int, int] | Tuple[ + None, None, None]: """ 处理匹配 :param m: re模块的匹配对象 @@ -156,7 +177,8 @@ class ID(InlineProcessor): self.property = property_ self.value = value - def handleMatch(self, m: Match[str], data: str) -> Tuple[xml.etree.ElementTree.Element, int, int] | Tuple[None, None, None]: + def handleMatch(self, m: Match[str], data: str) -> Tuple[xml.etree.ElementTree.Element, int, int] | Tuple[ + None, None, None]: """ 处理匹配 :param m: re模块的匹配对象 @@ -182,7 +204,8 @@ class Emoji(InlineProcessor): """ super().__init__(pattern) - def handleMatch(self, m: Match[str], data: str) -> Tuple[xml.etree.ElementTree.Element, int, int] | Tuple[None, None, None]: + def handleMatch(self, m: Match[str], data: str) -> Tuple[xml.etree.ElementTree.Element, int, int] | Tuple[ + None, None, None]: """ 处理匹配 :param m: re模块的匹配对象 @@ -272,7 +295,8 @@ class BoxBlock(BlockProcessor): class _Anchor(InlineProcessor): - def handleMatch(self, m: Match[str], data: str) -> Tuple[xml.etree.ElementTree.Element, int, int] | Tuple[None, None, None]: + def handleMatch(self, m: Match[str], data: str) -> Tuple[xml.etree.ElementTree.Element, int, int] | Tuple[ + None, None, None]: """ 处理匹配 :param m: re模块的匹配对象 @@ -357,6 +381,7 @@ class CodeBlock(Treeprocessor): """ 渲染单行代码 """ + def run(self, root: xml.etree.ElementTree.Element): for code in root: print(code.text) @@ -364,6 +389,7 @@ class CodeBlock(Treeprocessor): class Pre(Extension): """预处理""" + def __init__(self, variable: Variable): """ 初始化 @@ -401,7 +427,7 @@ class Basic(Extension): md.inlinePatterns.register(ID( r'\[(.*?)]-\((.*?)\)', tag='span', property_='title'), 'hide', 180 ) # [在指定的文本里面隐藏一段文本]-(只有鼠标放在上面才会显示隐藏文本) - md.inlinePatterns.register(Emoji(r':(.+?):'), 'emoji', 181) # 将emoji短代码转换为emoji字符 + # md.inlinePatterns.register(Emoji(r':(.+?):'), 'emoji', 181) # 将emoji短代码转换为emoji字符 md.parser.blockprocessors.register(Syllabus(md.parser), 'syllabus', 182) # 渲染提纲 @@ -475,8 +501,8 @@ class Code(Extension): :param md: 转换器 """ md.registerExtension(self) # 注册扩展 - md.treeprocessors.register(CodeLine(variable=self.variable), 'code_line', 0) # 渲染单行代码块 - md.treeprocessors.register(CodeBlock(), 'code_block', 1000) # 渲染多行代码块 + # md.treeprocessors.register(CodeLine(variable=self.variable), 'code_line', 0) # 渲染单行代码块 + # md.treeprocessors.register(CodeBlock(), 'code_block', 1000) # 渲染多行代码块 def main(text: str, variable: Variable = None) -> Tuple[str, Variable]: diff --git a/README.html b/README.html index cfb5dc7..0d26767 100644 --- a/README.html +++ b/README.html @@ -120,6 +120,15 @@
  • 15 内部链接
  • 16 变量
  • 17 属性设置
  • +
  • 18 超级块 +
  • +
  • 19 批评
  • CrossDown

    @@ -168,87 +177,78 @@

    4 代码块

    4.1 单行

    4.1.1 LaTex

    -

    这是\(CO_2\)二氧化碳

    -

    这是\(H_2O\)

    -

    \(\lg\left(\frac{目标生物的理智值}{稳定折磨型工具人的理智值}\right)\)

    +

    这是$CO_2$二氧化碳

    +

    这是$H_2O$

    +

    $\lg\left(\frac{目标生物的理智值}{稳定折磨型工具人的理智值}\right)$

    4.1.2 函数

    -

    Base64 函数图片 // 不定义范围

    -

    Base64 函数图片 // 定义了x范围

    -

    Base64 函数图片 // 定义了y范围

    +

    ¥y=x*2+1¥ // 不定义范围

    +

    ¥y=x**2¥€-50,50€ // 定义了x范围

    +

    ¥y=x**3¥€-50,50|-100,100€ // 定义了y范围

    4.1.3 强调

    -

    强调文本

    -

    强调值

    +

    {强调文本}

    +

    {强调变量}

    4.2 多行

    4.2.1 YAML

    -
    A:
    -        1. a
    -        2. b
    -        3. c
    -    B:
    -        - a
    -        - b
    -        - c
    -    强调值:
    -        - a
    -        - b
    -    
    - +
    A:
    +        1. a
    +        2. b
    +        3. c
    +    B:
    +        - a
    +        - b
    +        - c
    +    强调值:
    +        - a
    +        - b
    +    

    4.2.2 Python

    -
    #! usr/bin/python3.11
    -    def main():
    -        print('CrossDown')
    -    
    - +
    #! usr/bin/python3.11
    +    def main():
    +        print('CrossDown')
    +    

    4.2.3 Mermaid

    -
    graph TD  
    +    
    graph TD  
             A[开始]-->B[流程]  
             B-->C{判断}  
             C-->|结果1|D[结束1]  
             C-->|结果2|E[结束2]
    -    
    - +

    4.2.4 shell

    -
    cd ../..
    +    
    cd ../..
         ls
    -    
    - +

    4.2.5 latex

    -
    \documentclass{article}  
    -    \title{我的第一个LaTeX文档}  
    -    \author{作者姓名}  
    -    \date{\today}  
    -    
    -    \begin{document}  
    -    
    -    \maketitle  
    -    
    -    这是我的第一个LaTeX文档。它包含了一个标题、作者信息、日期和一个简单的正文部分。  
    -    
    -    \section{引言}  
    -    
    -    这是引言部分,可以简要介绍文档的主题和目的。  
    -    
    -    \section{正文}  
    -    
    -    这是正文部分,可以详细阐述你的观点或研究内容。你可以根据需要添加更多的章节和子章节。  
    -    
    -    \subsection{子章节示例}  
    -    
    -    这是一个子章节的示例,用于展示如何在LaTeX文档中创建层次结构。  
    -    
    -    \end{document}
    -    
    - +
    +
    + E(\mathbf{v}, \mathbf{h}) = -\sum_{i,j}w_{ij}v_i h_j - \sum_i b_i v_i - \sum_j c_j h_j +
    + +
    +
    +
    3 < 4
    + +
    +
    +
    \begin{align} + p(v_i=1|\mathbf{h}) & = \sigma\left(\sum_j w_{ij}h_j + b_i\right) \\ + p(h_j=1|\mathbf{v}) & = \sigma\left(\sum_i w_{ij}v_i + c_j\right) + \end{align}
    + +
    +

    行内公式: p(x|y) = \frac{p(y|x)p(x)}{p(y)}

    4.2.6 HTML

    -
    *斜体***粗体**~下划线~~~删除线~~==高亮==
    -    
    - +
    *斜体***粗体**~下划线~~~删除线~~==高亮==
    +    

    4.2.7 未知语言

    -
    #! usr/bin/python3.11
    +    
    #! usr/bin/python3.11
         def main():
    -        print('CrossDown')
    -    
    - + print('CrossDown') +

    5 转义

    \

    \a

    @@ -328,7 +328,7 @@
  • c
  • -
    强调值
    +
    {强调变量}