From 58ef10b4037bae74b6fd9ed0a8b24cfba8999183 Mon Sep 17 00:00:00 2001 From: crossdark Date: Sun, 29 Sep 2024 19:30:57 +0800 Subject: [PATCH] =?UTF-8?q?0.11.2=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CrossDown.py | 90 ++++++++++++++++++++++++++++------------------------ README.html | 28 +++++++--------- setup.py | 4 ++- 3 files changed, 63 insertions(+), 59 deletions(-) diff --git a/CrossDown.py b/CrossDown.py index 1d14e4d..eddaf31 100644 --- a/CrossDown.py +++ b/CrossDown.py @@ -6,48 +6,53 @@ import markdown try: # 检测当前平台是否支持扩展语法 import CrossMore + EXTRA_ABLE = True except ModuleNotFoundError: EXTRA_ABLE = False __all__ = [ - 'main' + 'main', # 主函数 + 'indent', # 添加空格 + 'body', # 主题函数 + 'Style', # 风格 + 'Value', # 变量 + 'CodeBlock', # 代码块 + 'Syllabus', # 提纲 + 'Basic', # 基础 + 'HEAD', + 'BODY', ] - -__version__ = '0.11.1' +__version__ = '0.11.2' __author__ = 'CrossDark' __email__ = 'liuhanbo333@icloud.com' __source__ = 'https://crossdark.net/' __license__ = """MIT""" +HEAD = ( + '', + '', + '', + '', + '', + '' +) -HEAD = """ - - - - - - -""" - - -BODY = """ - - -""" +BODY = ( + '', + '', +) class Style: @@ -234,11 +239,11 @@ class Syllabus: fr'{"#" * len(match.groups()[0].split("."))} \1{{#' + match.groups()[0] + '}', origen) if match is not None else origen) # 对于不是提纲的行,直接返回原始字符 ((lambda x: re.match(r'^([\d.]+) ', x) # 判断是否是提纲 - if not any((x.startswith('.'), # 以.开头 - re.search('\. ', x) is not None, # 存在.+空格 - re.search('\.{2,}', x), # 存在连续的. - )) - else None)(line), line) # 排除.在提纲号开头或结尾的情况 + if not any((x.startswith('.'), # 以.开头 + re.search('\. ', x) is not None, # 存在.+空格 + re.search('\.{2,}', x), # 存在连续的. + )) + else None)(line), line) # 排除.在提纲号开头或结尾的情况 for line in self.text.splitlines() # 分割并遍历文本的每一行 ]) @@ -266,16 +271,17 @@ class Basic: return re.sub('// .*?\n', '\n', text) -def indent(input_string: str, indent_spaces: int = 4) -> str: +def indent(input_: Union[str, List, Tuple], indent_spaces: int = 4) -> str: """ 给字符串中的每一行前面加上缩进。 - :param input_string: 原始字符串,可以包含多行。 + :param input_: 原始字符串,可以包含多行。 :param indent_spaces: 每行前面要添加的空格数,默认为4。 :return: 带缩进的新字符串。 """ - # 使用字符串的splitlines()方法分割原始字符串为行列表 + # 使用字符串的splitlines()方法分割原始字符串为行列表,如果是可迭代对象则直接遍历 # 遍历行列表,给每行前面加上相应的缩进,并重新组合成字符串 - return "\n".join(f"{' ' * indent_spaces}{line}" for line in input_string.splitlines()) + return "\n".join( + f"{' ' * indent_spaces}{line}" for line in (lambda x: x.splitlines() if isinstance(x, str) else x)(input_)) def body(text: str) -> Tuple[str, Dict[str, str]]: @@ -324,12 +330,12 @@ if __name__ == '__main__': UTF-8编码示例 - {indent(HEAD)} +{indent(HEAD)} - {indent(BODY)} - {indent(cd, 4)} +{indent(BODY)} +{indent(cd, 4)} """) diff --git a/README.html b/README.html index 17cbbd4..8b77047 100644 --- a/README.html +++ b/README.html @@ -4,33 +4,29 @@ UTF-8编码示例 - - + + - - - -
+
  • CrossDown
  • 1 基本语法
      diff --git a/setup.py b/setup.py index 05697d0..db7a1d8 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ with open("README.md", "r") as fh: setuptools.setup( name="CrossDown", - version="0.11.0", + version="0.11.2", author="CrossDark", author_email="liuhanbo333@icloud.com", description="CrossDark's MarkDown", @@ -18,6 +18,8 @@ setuptools.setup( ], install_requires=[ 'markdown', + 'matplotlib', + 'numpy', ], classifiers=[ 'Programming Language :: Python :: 3.11',