0.11.1 Emoji添加

This commit is contained in:
跨越晨昏 2024-09-29 19:10:34 +08:00
parent 3cac20d7f7
commit 4bda51db70
4 changed files with 32 additions and 17 deletions

View File

@ -1,6 +1,7 @@
import time
from typing import * from typing import *
import re import re
import emoji
import markdown import markdown
try: # 检测当前平台是否支持扩展语法 try: # 检测当前平台是否支持扩展语法
@ -9,6 +10,16 @@ try: # 检测当前平台是否支持扩展语法
except ModuleNotFoundError: except ModuleNotFoundError:
EXTRA_ABLE = False EXTRA_ABLE = False
__all__ = [
'main'
]
__version__ = '0.11.1'
__author__ = 'CrossDark'
__email__ = 'liuhanbo333@icloud.com'
__source__ = 'https://crossdark.net/'
__license__ = """MIT"""
HEAD = """ HEAD = """
<script type="text/javascript" async <script type="text/javascript" async
@ -86,12 +97,12 @@ class Style:
""" """
self.text = re.sub(r'\[(.*?)]-\((.*?)\)', r'<span title="\2">\1</span>', self.text) self.text = re.sub(r'\[(.*?)]-\((.*?)\)', r'<span title="\2">\1</span>', self.text)
def __call__(self, *args, **kwargs): def __call__(self, *args, **kwargs) -> str:
""" """
一键运行 一键运行
:param args: :param args:
:param kwargs: :param kwargs:
:return: :return: 处理后的文本
""" """
self.strikethrough() self.strikethrough()
self.underline() self.underline()
@ -141,7 +152,7 @@ class CodeBlock:
self.codes = [i for i in re.findall(r'`([^`]*)`', text) if i != ''] # 找出代码快 self.codes = [i for i in re.findall(r'`([^`]*)`', text) if i != ''] # 找出代码快
self.text = re.sub(r'``', '', text) # 移除代码标识` self.text = re.sub(r'``', '', text) # 移除代码标识`
def __call__(self, *args, **kwargs): def __call__(self, *args, **kwargs) -> str:
""" """
临时移除代码块 临时移除代码块
:param args: :param args:
@ -195,7 +206,7 @@ class CodeBlock:
else: # 是突出块 else: # 是突出块
self.codes[index] = f'<span class="block">{code}</span>' self.codes[index] = f'<span class="block">{code}</span>'
def restore(self, new_text: str): def restore(self, new_text: str) -> str:
""" """
将渲染好的代码重新放回处理好的正文 将渲染好的代码重新放回处理好的正文
:param new_text: 处理好的正文 :param new_text: 处理好的正文
@ -255,7 +266,7 @@ class Basic:
return re.sub('// .*?\n', '\n', text) return re.sub('// .*?\n', '\n', text)
def indent(input_string: str, indent_spaces: int = 4): def indent(input_string: str, indent_spaces: int = 4) -> str:
""" """
给字符串中的每一行前面加上缩进 给字符串中的每一行前面加上缩进
:param input_string: 原始字符串可以包含多行 :param input_string: 原始字符串可以包含多行
@ -263,12 +274,8 @@ def indent(input_string: str, indent_spaces: int = 4):
:return: 带缩进的新字符串 :return: 带缩进的新字符串
""" """
# 使用字符串的splitlines()方法分割原始字符串为行列表 # 使用字符串的splitlines()方法分割原始字符串为行列表
lines = input_string.splitlines()
# 遍历行列表,给每行前面加上相应的缩进,并重新组合成字符串 # 遍历行列表,给每行前面加上相应的缩进,并重新组合成字符串
indented_string = "\n".join(f"{' ' * indent_spaces}{line}" for line in lines) return "\n".join(f"{' ' * indent_spaces}{line}" for line in input_string.splitlines())
return indented_string
def body(text: str) -> Tuple[str, Dict[str, str]]: def body(text: str) -> Tuple[str, Dict[str, str]]:
@ -288,11 +295,12 @@ def body(text: str) -> Tuple[str, Dict[str, str]]:
'markdown.extensions.admonition', # 警告扩展 'markdown.extensions.admonition', # 警告扩展
'markdown.extensions.meta', # 元数据 'markdown.extensions.meta', # 元数据
]) # 渲染标准markdown ]) # 渲染标准markdown
text = emoji.emojize(text) # 渲染Emoji
return text, values return text, values
def main(origen: str): def main(origen: str):
# 预处理 # 预处理
origen = Basic.strong_annotation(origen) # 移除强注释 origen = Basic.strong_annotation(origen) # 移除强注释
code_block = CodeBlock(origen) # 获取代码内容 code_block = CodeBlock(origen) # 获取代码内容
text = code_block() # 暂时移除代码 text = code_block() # 暂时移除代码
@ -304,6 +312,9 @@ def main(origen: str):
if __name__ == '__main__': if __name__ == '__main__':
# 开始计时
start_time = time.perf_counter_ns()
# 主程序
with open('README.md', encoding='utf-8') as test: with open('README.md', encoding='utf-8') as test:
cd = main(test.read()) cd = main(test.read())
with open('README.html', 'w', encoding='utf-8') as html: with open('README.html', 'w', encoding='utf-8') as html:
@ -322,3 +333,7 @@ if __name__ == '__main__':
</body> </body>
</html> </html>
""") """)
# 停止计时
end_time = time.perf_counter_ns()
# 输出用时
print("运行时间: {:.9f}".format((end_time - start_time) / 1e9))

View File

@ -275,7 +275,7 @@
<p class="admonition-title">这是一条警告</p> <p class="admonition-title">这是一条警告</p>
</div> </div>
<h1 id="11-emoji">11<span id="11"></span> Emoji</h1> <h1 id="11-emoji">11<span id="11"></span> Emoji</h1>
<p>:heart:</p> <p>🚴</p>
<p>:smile:</p> <p>😃</p>
</body> </body>
</html> </html>

View File

@ -213,6 +213,6 @@ graph LR
11 Emoji 11 Emoji
:heart: :person_biking:
:smile: :grinning_face_with_big_eyes:

View File

@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
setuptools.setup( setuptools.setup(
name="CrossDown", name="CrossDown",
version="0.10.0", version="0.11.0",
author="CrossDark", author="CrossDark",
author_email="liuhanbo333@icloud.com", author_email="liuhanbo333@icloud.com",
description="CrossDark's MarkDown", description="CrossDark's MarkDown",