forked from CrossDark/CrossDown
V0.6
This commit is contained in:
parent
b35d61dec7
commit
e181c505f9
15
CrossDown.py
15
CrossDown.py
@ -118,9 +118,9 @@ class Style:
|
||||
return self.text
|
||||
|
||||
|
||||
class Function:
|
||||
class Link:
|
||||
"""
|
||||
添加特殊功能
|
||||
添加链接
|
||||
"""
|
||||
|
||||
def __init__(self, text: str):
|
||||
@ -158,7 +158,7 @@ class Function:
|
||||
|
||||
class Value:
|
||||
"""
|
||||
定义: {变量名}: 值
|
||||
定义: {变量名} = 值
|
||||
赋值: {变量或锚点名}
|
||||
锚点: #{锚点名}
|
||||
"""
|
||||
@ -305,7 +305,7 @@ class Syllabus:
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
for num, txt in self.syllabus.items():
|
||||
self.text = re.sub(f'{".".join(num)} {txt}', f'<h{len(num)}>{".".join(num)} {txt}#{{' + '.'.join(num) + f'}}</h{len(num)}>', self.text) # 按照层级为提纲添加不同等级的标题并创建锚点
|
||||
self.text = re.sub(f'{".".join(num)} {re.escape(txt)}', f'<h{len(num)}>{".".join(num)} {txt}#{{' + '.'.join(num) + f'}}</h{len(num)}>', self.text) # 按照层级为提纲添加不同等级的标题并创建锚点
|
||||
return self.text
|
||||
|
||||
|
||||
@ -357,7 +357,6 @@ def add_indent_to_string(input_string: str, indent_spaces: int = 4):
|
||||
给字符串中的每一行前面加上缩进。
|
||||
:param input_string: 原始字符串,可以包含多行。
|
||||
:param indent_spaces: 每行前面要添加的空格数,默认为4。
|
||||
|
||||
:return: 带缩进的新字符串。
|
||||
"""
|
||||
# 使用字符串的splitlines()方法分割原始字符串为行列表
|
||||
@ -381,7 +380,7 @@ def body(text: str) -> Tuple[str, Dict[str, str]]:
|
||||
text, values = Value(text)() # 提取变量并赋值到文本中
|
||||
text = Header(text)() # 渲染标题
|
||||
text = Style(text)() # 渲染字体样式
|
||||
text = Function(text)() # 渲染特殊功能
|
||||
text = Link(text)() # 渲染特殊功能
|
||||
text = Cite(text)() # 渲染引用
|
||||
text = Basic(text)() # 渲染基础格式
|
||||
|
||||
@ -402,9 +401,9 @@ def main(origen: str):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
with open('test.md', encoding='utf-8') as test:
|
||||
with open('Example.mdc', encoding='utf-8') as test:
|
||||
cd = main(test.read())
|
||||
with open('test.html', 'w', encoding='utf-8') as html:
|
||||
with open('Example.html', 'w', encoding='utf-8') as html:
|
||||
html.write(f"""<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
|
73
Example.mdc
73
Example.mdc
@ -0,0 +1,73 @@
|
||||
# CrossDown示例
|
||||
1 基本语法
|
||||
1.1 标题
|
||||
# 一级标题
|
||||
## 二级标题
|
||||
### 三级标题
|
||||
#### 四级标题
|
||||
##### 五级标题
|
||||
###### 六级标题
|
||||
1.2 样式
|
||||
1.2.1 *斜体*
|
||||
1.2.2 **粗体**
|
||||
1.2.3 ***粗斜体***
|
||||
1.2.4 ~下划线~
|
||||
1.2.5 ~~删除线~~
|
||||
1.2.6 ==高亮==
|
||||
1.2.7 [在文本的正上方添加一行小文本]^(主要用于标拼音)
|
||||
1.2.8 [在指定的文本里面隐藏一段文本]-(只有鼠标放在上面才会显示隐藏文本)
|
||||
1.2.9 分割线
|
||||
---
|
||||
___
|
||||
***
|
||||
1.3 链接
|
||||
1.3.1 [链接文本](链接地址)
|
||||
1.3.2 ![链接图片](链接地址)
|
||||
2 变量
|
||||
2.1 定义
|
||||
{变量名} = 值
|
||||
2.2 赋值
|
||||
{变量名} {锚点名}
|
||||
2.3 添加锚点
|
||||
#{锚点名}
|
||||
3 代码块
|
||||
3.1 `单行`
|
||||
3.1.1 LaTex
|
||||
`$CO^2$`
|
||||
3.2 多行
|
||||
3.2.1 YAML
|
||||
`
|
||||
A:
|
||||
1. a
|
||||
2. b
|
||||
3. c
|
||||
B:
|
||||
- a
|
||||
- b
|
||||
- c
|
||||
`
|
||||
3.2.2 Python
|
||||
`python
|
||||
print('CrossDown')
|
||||
`
|
||||
3.2.3 Mermaid
|
||||
`mermaid
|
||||
graph LR
|
||||
A-->B
|
||||
A-->C
|
||||
B-->D
|
||||
C-->D
|
||||
`
|
||||
4 转义
|
||||
\\
|
||||
5 引用
|
||||
> 渲染引用 --[引用来源]
|
||||
6 提纲
|
||||
7 注释
|
||||
7.1 强注释
|
||||
|=
|
||||
无论如何都会被移除
|
||||
`放在代码块里也没用`
|
||||
=|
|
||||
7.2 弱注释
|
||||
只有在 // 后面才会被移除
|
Loading…
Reference in New Issue
Block a user