From 62abbad860cb11dec7a142dde4ea7ff8886d6767 Mon Sep 17 00:00:00 2001 From: crossdark Date: Sat, 26 Oct 2024 18:37:34 +0800 Subject: [PATCH] =?UTF-8?q?3.2=20=E5=B7=AE=E4=B8=8D=E5=A4=9A=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CrossDown/Core.py | 102 ++++++++++------ README.html | 306 +++++++++++++++++++++++++++++++++------------- README.md | 123 +++++++++++++------ Static/styles.css | 140 ++++++++++----------- setup.py | 2 +- 5 files changed, 444 insertions(+), 229 deletions(-) diff --git a/CrossDown/Core.py b/CrossDown/Core.py index fa4ce36..6dc97f4 100644 --- a/CrossDown/Core.py +++ b/CrossDown/Core.py @@ -1,15 +1,26 @@ from markdown.extensions import Extension, extra, admonition, meta, sane_lists, toc, wikilinks, codehilite, legacy_attrs +from pymdownx.extra import ExtraExtension 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.caret import InsertSupExtension from pymdownx.critic import CriticExtension +from pymdownx.highlight import HighlightExtension +from pymdownx.inlinehilite import InlineHiliteExtension +from pymdownx.keys import KeysExtension +from pymdownx.mark import MarkExtension +from pymdownx.progressbar import ProgressBarExtension +from pymdownx.smartsymbols import SmartSymbolsExtension +from pymdownx.superfences import SuperFencesCodeExtension, fence_div_format +from pymdownx.tasklist import TasklistExtension +from pymdownx.tilde import DeleteSubExtension +from pymdownx.fancylists import FancyListExtension +from pymdownx.saneheaders import SaneHeadersExtension from pygments.formatters import HtmlFormatter @@ -56,30 +67,6 @@ class HighlightHtmlFormatter(HtmlFormatter): yield 0, '' -Extensions = { - # 自带 - '基本扩展': extra.ExtraExtension(fenced_code={'lang_prefix': ''}), - # '警告扩展': admonition.AdmonitionExtension(), - '元数据': meta.MetaExtension(), - # '能列表': sane_lists.SaneListExtension(), - '目录': toc.TocExtension(), - '内部链接': wikilinks.WikiLinkExtension(), - # '代码高亮': codehilite.CodeHiliteExtension(guess_lang=False, pygments_formatter=HighlightHtmlFormatter), - '属性设置': legacy_attrs.LegacyAttrExtension(), - - # pymdownx - '超级数学': ArithmatexExtension(), - 'EMOJI': EmojiExtension(), - '块扩展': BlocksExtension(), - '警告': AdmonitionExtension(), - '定义列表': DefinitionExtension(), - '详情': DetailsExtension(), - 'HTML': HTMLExtension(), - '标签': TabExtension(), - '批评': CriticExtension(), -} - - class PreProcess(Preprocessor): """预处理""" @@ -418,15 +405,15 @@ class Basic(Extension): :param md: 转换器 """ md.registerExtension(self) # 注册扩展 - md.inlinePatterns.register(Simple(r'~~(.*?)~~', tag='s'), 'strikethrough', 176) # ~~删除线~~ - md.inlinePatterns.register(Simple(r'~(.*?)~', tag='u'), 'underline', 177) # ~下划线~ - md.inlinePatterns.register(Simple(r'==(.*?)==', tag='mark'), 'high_light', 178) # ==高亮== - md.inlinePatterns.register(Nest( - r'\[(.*?)]\^\((.*?)\)', outer_tag='ruby', inner_tag='rt'), 'up', 179 - ) # [在文本的正上方添加一行小文本]^(主要用于标拼音) - md.inlinePatterns.register(ID( - r'\[(.*?)]-\((.*?)\)', tag='span', property_='title'), 'hide', 180 - ) # [在指定的文本里面隐藏一段文本]-(只有鼠标放在上面才会显示隐藏文本) + # md.inlinePatterns.register(Simple(r'~~(.*?)~~', tag='s'), 'strikethrough', 176) # ~~删除线~~ + # md.inlinePatterns.register(Simple(r'~(.*?)~', tag='u'), 'underline', 177) # ~下划线~ + # md.inlinePatterns.register(Simple(r'==(.*?)==', tag='mark'), 'high_light', 178) # ==高亮== + # md.inlinePatterns.register(Nest( + # r'\[(.*?)]\^\((.*?)\)', outer_tag='ruby', inner_tag='rt'), 'up', 179 + # ) # [在文本的正上方添加一行小文本]^(主要用于标拼音) + # md.inlinePatterns.register(ID( + # r'\[(.*?)]-\((.*?)\)', tag='span', property_='title'), 'hide', 180 + # ) # [在指定的文本里面隐藏一段文本]-(只有鼠标放在上面才会显示隐藏文本) # md.inlinePatterns.register(Emoji(r':(.+?):'), 'emoji', 181) # 将emoji短代码转换为emoji字符 md.parser.blockprocessors.register(Syllabus(md.parser), 'syllabus', 182) # 渲染提纲 @@ -505,6 +492,49 @@ class Code(Extension): # md.treeprocessors.register(CodeBlock(), 'code_block', 1000) # 渲染多行代码块 +Extensions = { + # 自带 + '元数据': meta.MetaExtension(), + '目录': toc.TocExtension(), + '内部链接': wikilinks.WikiLinkExtension(), + '属性设置': legacy_attrs.LegacyAttrExtension(), + + # pymdownx + '基本扩展': ExtraExtension(), + '超级数学': ArithmatexExtension(), + 'EMOJI': EmojiExtension(), + '块扩展': BlocksExtension(), + '警告': AdmonitionExtension(), + '详情': DetailsExtension(), + 'HTML': HTMLExtension(), + '标签': TabExtension(), + '批评': CriticExtension(), + '代码高亮': HighlightExtension(), + '行内高亮': InlineHiliteExtension(), + '按键风格': KeysExtension(), + '高亮': MarkExtension(), + '进度条': ProgressBarExtension(), + '高级符号': SmartSymbolsExtension(), + '超级代码块': SuperFencesCodeExtension( + custom_fences=[ # 渲染mermaid + { + 'name': 'mermaid', + 'class': 'mermaid', + 'format': fence_div_format + } + ] + ), + '任务列表': TasklistExtension(clickable_checkbox=True), + '下标': DeleteSubExtension(), + '上标': InsertSupExtension(), + '高级列表': FancyListExtension(), + '高级标题': SaneHeadersExtension(), + + # 自定义 + '基本风格': Basic(), +} + + def main(text: str, variable: Variable = None) -> Tuple[str, Variable]: """ 主函数 @@ -514,5 +544,5 @@ def main(text: str, variable: Variable = None) -> Tuple[str, Variable]: """ if variable is None: variable = {} - md = Markdown(extensions=[Pre(variable=variable), Basic(), Anchor()] + list(Extensions.values()) + [Code(variable=variable)]) + md = Markdown(extensions=list(Extensions.values())) return md.convert(text), md.Meta diff --git a/README.html b/README.html index 0d26767..36b946b 100644 --- a/README.html +++ b/README.html @@ -36,12 +36,14 @@
  • 1.2.1 斜体
  • 1.2.2 粗体
  • 1.2.3 粗斜体
  • -
  • 1.2.4 下划线
  • +
  • 1.2.4 下标
  • 1.2.5 删除线
  • 1.2.6 高亮
  • -
  • 1.2.7 在文本的正上方添加一行小文本主要用于标拼音
  • -
  • 1.2.8 在指定的文本里面隐藏一段文本
  • +
  • 1.2.7 [在文本的正上方添加一行小文本]^(主要用于标拼音)
  • +
  • 1.2.8 [在指定的文本里面隐藏一段文本]-(只有鼠标放在上面才会显示隐藏文本)
  • 1.2.9 分割线
  • +
  • 1.2.10 上标
  • +
  • 1.2.11 下划线
  • 1.3 链接