V0.6.1转义好像可以了
This commit is contained in:
parent
57ff58ddbe
commit
4f9c99d353
28
CrossDown.py
28
CrossDown.py
@ -254,9 +254,8 @@ class Escape:
|
||||
"""
|
||||
self.text = text
|
||||
self.escapes = {
|
||||
i: f'\0\1\2{i}\2\1\0' for i in re.findall(r'\\(.)', text)
|
||||
i: f'\0\1\2{i}\2\1\0' for i in re.findall(r'(\\.)', text)
|
||||
} # 找出要转义的字符
|
||||
print(self.escapes)
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
"""
|
||||
@ -266,8 +265,19 @@ class Escape:
|
||||
:return: 不含代码的文本
|
||||
"""
|
||||
# TODO
|
||||
for index, item in enumerate(self.escapes): # 替换代码块为-@@-(ID)-@@-
|
||||
self.text = re.sub(fr'{index}', f'\0\1\2{index}\2\1\0', self.text) # 同时转译特殊字符
|
||||
for index, item in self.escapes.items(): # 替换代码块为\0\1\2(id)\2\1\0
|
||||
self.text = re.sub(fr'{re.escape(index)}', item, self.text) # 同时转译特殊字符
|
||||
print(item)
|
||||
return self.text
|
||||
|
||||
def back(self, text):
|
||||
"""
|
||||
将被转义的字符放回文本中
|
||||
:param text: 新文本
|
||||
:return: 放回转义字符的文本
|
||||
"""
|
||||
for index, item in self.escapes.items(): # 替换\0\1\2(id)\2\1\0为转义字符
|
||||
self.text = re.sub(item, fr'{index}', text) # 同时转译特殊字符
|
||||
return self.text
|
||||
|
||||
def restore(self, new_text: str):
|
||||
@ -329,7 +339,7 @@ class Basic:
|
||||
:param text: 原始文本
|
||||
:return: 移除弱注释后的文本
|
||||
"""
|
||||
return re.sub('// .*?\n', '', text)
|
||||
return re.sub('// .*?\n', '\n', text)
|
||||
|
||||
def paragraph(self):
|
||||
"""
|
||||
@ -374,7 +384,8 @@ def body(text: str) -> Tuple[str, Dict[str, str]]:
|
||||
:param text: 输入正文
|
||||
:return: 输出渲染后的正文
|
||||
"""
|
||||
Escape(text)
|
||||
escape = Escape(text) # 转义
|
||||
text = escape()
|
||||
text = Basic.week_annotation(text) # 移除弱注释
|
||||
text = Syllabus(text)() # 渲染提纲
|
||||
text, values = Value(text)() # 提取变量并赋值到文本中
|
||||
@ -383,6 +394,7 @@ def body(text: str) -> Tuple[str, Dict[str, str]]:
|
||||
text = Link(text)() # 渲染特殊功能
|
||||
text = Cite(text)() # 渲染引用
|
||||
text = Basic(text)() # 渲染基础格式
|
||||
text = escape.back(text)
|
||||
|
||||
# text = Basic.paragraph(text) # 渲染段落
|
||||
return text, values
|
||||
@ -401,9 +413,9 @@ def main(origen: str):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
with open('Example.mdc', encoding='utf-8') as test:
|
||||
with open('README.md', encoding='utf-8') as test:
|
||||
cd = main(test.read())
|
||||
with open('Example.html', 'w', encoding='utf-8') as html:
|
||||
with open('README.html', 'w', encoding='utf-8') as html:
|
||||
html.write(f"""<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
|
54
Editor.py
Normal file
54
Editor.py
Normal file
@ -0,0 +1,54 @@
|
||||
import sys
|
||||
from PyQt6.QtWidgets import QApplication, QMainWindow, QTextEdit, QAction, QMenuBar, QMenu, QFileDialog
|
||||
|
||||
|
||||
class TextEditor(QMainWindow):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
# 设置窗口标题和初始大小
|
||||
self.setWindowTitle('PyQt6 Text Editor')
|
||||
self.setGeometry(100, 100, 800, 600)
|
||||
|
||||
# 创建文本编辑器控件
|
||||
self.text_edit = QTextEdit(self)
|
||||
self.setCentralWidget(self.text_edit)
|
||||
|
||||
# 创建菜单栏和文件菜单
|
||||
self.menu_bar = QMenuBar(self)
|
||||
self.setMenuBar(self.menu_bar)
|
||||
|
||||
file_menu = QMenu('File', self)
|
||||
self.menu_bar.addMenu(file_menu)
|
||||
|
||||
# 创建动作并添加到文件菜单
|
||||
open_action = QAction('Open', self)
|
||||
open_action.triggered.connect(self.open_file)
|
||||
file_menu.addAction(open_action)
|
||||
|
||||
save_action = QAction('Save', self)
|
||||
save_action.triggered.connect(self.save_file)
|
||||
file_menu.addAction(save_action)
|
||||
|
||||
exit_action = QAction('Exit', self)
|
||||
exit_action.triggered.connect(self.close)
|
||||
file_menu.addAction(exit_action)
|
||||
|
||||
def open_file(self):
|
||||
file_name, _ = QFileDialog.getOpenFileName(self, 'Open File', '', "Text Files (*.txt *.py)")
|
||||
if file_name:
|
||||
with open(file_name, 'r') as file:
|
||||
self.text_edit.setPlainText(file.read())
|
||||
|
||||
def save_file(self):
|
||||
file_name, _ = QFileDialog.getSaveFileName(self, 'Save File', '', "Text Files (*.txt *.py)")
|
||||
if file_name:
|
||||
with open(file_name, 'w') as file:
|
||||
file.write(self.text_edit.toPlainText())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = QApplication(sys.argv)
|
||||
editor = TextEditor()
|
||||
editor.show()
|
||||
sys.exit(app.exec())
|
16
README.html
16
README.html
@ -23,7 +23,9 @@
|
||||
<script>
|
||||
mermaid.initialize({startOnLoad:true});
|
||||
</script>
|
||||
<h1>CrossDown示例</h1>
|
||||
<h1>CrossDown</h1>
|
||||
<p>自制的markdown,添加了一些自定义的语法</p>
|
||||
<p>效果请见<a href="https://github.com/CrossDark/CrossDown/blob/main/README.html">README.html</a></p>
|
||||
<h1>1 基本语法<span id="1"></span></h1>
|
||||
<h2>1.1 标题<span id="1.1"></span></h2>
|
||||
<h1>一级标题</h1>
|
||||
@ -43,8 +45,11 @@
|
||||
<h3>1.2.8 <span title="只有鼠标放在上面才会显示隐藏文本">在指定的文本里面隐藏一段文本</span><span id="1.2.8"></span></h3>
|
||||
<h3>1.2.9 分割线<span id="1.2.9"></span></h3>
|
||||
<hr><hr><hr><h2>1.3 链接<span id="1.3"></span></h2>
|
||||
<h3>1.3.1 <a href="链接地址">链接文本</a><span id="1.3.1"></span></h3>
|
||||
<h3>1.3.2 <img src="链接地址" alt="链接图片"><span id="1.3.2"></span></h3>
|
||||
<h3>1.3.1 普通链接<span id="1.3.1"></span></h3>
|
||||
<a href="链接地址">链接文本</a>
|
||||
<a href="https://crossdark.com">CrossDark</a>
|
||||
<h3>1.3.2 图片<span id="1.3.2"></span></h3>
|
||||
<p><img src="链接地址" alt="链接图片"></p>
|
||||
<h1>2 变量<span id="2"></span></h1>
|
||||
<h2>2.1 定义<span id="2.1"></span></h2>
|
||||
<h2>2.2 赋值<span id="2.2"></span></h2>
|
||||
@ -54,7 +59,7 @@
|
||||
<h1>3 代码块<span id="3"></span></h1>
|
||||
<h2>3.1 <span class="block">单行</span><span id="3.1"></span></h2>
|
||||
<h3>3.1.1 LaTex<span id="3.1.1"></span></h3>
|
||||
<p>\(CO^2\)</p>
|
||||
<p>\(CO_2\)</p>
|
||||
<h2>3.2 多行<span id="3.2"></span></h2>
|
||||
<h3>3.2.1 YAML<span id="3.2.1"></span></h3>
|
||||
<pre><code class="language-yaml">
|
||||
@ -80,12 +85,13 @@
|
||||
C-->D
|
||||
</div>
|
||||
<h1>4 转义<span id="4"></span></h1>
|
||||
<p>\\</p>
|
||||
\
|
||||
<h1>5 引用<span id="5"></span></h1>
|
||||
<blockquote>渲染引用<footer><cite>引用来源</cite></footer></blockquote><h1>6 提纲<span id="6"></span></h1>
|
||||
<h1>7 注释<span id="7"></span></h1>
|
||||
<h2>7.1 强注释<span id="7.1"></span></h2>
|
||||
<h2>7.2 弱注释<span id="7.2"></span></h2>
|
||||
<p>只有在 </p>
|
||||
<span class="block">// 代码中的注释弱不会被移除</span>
|
||||
</body>
|
||||
</html>
|
||||
|
10
README.md
10
README.md
@ -23,8 +23,11 @@
|
||||
___
|
||||
***
|
||||
1.3 链接
|
||||
1.3.1 [链接文本](链接地址)
|
||||
1.3.2 ![链接图片](链接地址)
|
||||
1.3.1 普通链接
|
||||
[链接文本](链接地址)
|
||||
[CrossDark](https://crossdark.com)
|
||||
1.3.2 图片
|
||||
![链接图片](链接地址)
|
||||
2 变量
|
||||
2.1 定义
|
||||
{变量名} = 值
|
||||
@ -35,7 +38,7 @@ ___
|
||||
3 代码块
|
||||
3.1 `单行`
|
||||
3.1.1 LaTex
|
||||
`$CO^2$`
|
||||
`$CO_2$`
|
||||
3.2 多行
|
||||
3.2.1 YAML
|
||||
`
|
||||
@ -73,3 +76,4 @@ graph LR
|
||||
=|
|
||||
7.2 弱注释
|
||||
只有在 // 后面才会被移除
|
||||
`// 代码中的注释弱不会被移除`
|
||||
|
Loading…
Reference in New Issue
Block a user