diff --git a/CrossDown.py b/CrossDown.py index 031941c..397cb54 100644 --- a/CrossDown.py +++ b/CrossDown.py @@ -3,8 +3,6 @@ import re import markdown -import MarkDown - class Header: def __init__(self, text: str): diff --git a/MarkDown.py b/MarkDown.py deleted file mode 100644 index 1cea752..0000000 --- a/MarkDown.py +++ /dev/null @@ -1,7 +0,0 @@ -import markdown - - -with open('README.md', encoding='utf-8') as text: - html = markdown.markdown(text.read(), extensions=['markdown.extensions.extra']) - print(html) - diff --git a/Output.md b/Output.md deleted file mode 100644 index 82b81e4..0000000 --- a/Output.md +++ /dev/null @@ -1,87 +0,0 @@ - - - - - - UTF-8编码示例 - - - - - - - - - - -

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

-

-    print('CrossDown')
-    
-

3.2.3 Mermaid

-
- graph LR - A-->B - A-->C - B-->D - C-->D -
-

4 转义

-

\\

-

5 引用

-
渲染引用

6 提纲

-

7 注释

-

7.1 强注释

diff --git a/Test.py b/Test.py new file mode 100644 index 0000000..cd535ae --- /dev/null +++ b/Test.py @@ -0,0 +1,79 @@ +import unittest +import markdown + + +def convert_markdown_to_html(markdown_text): + return markdown.markdown(markdown_text, extensions=['markdown.extensions.extra']) + + +class TestMarkdownToHtmlConversion(unittest.TestCase): + + def test_simple_conversion(self): + markdown_text = "# Hello, World!" + expected_html = "

Hello, World!

\n" + self.assert_conversion(markdown_text, expected_html) + + def test_paragraph_conversion(self): + markdown_text = "This is a paragraph." + expected_html = "

This is a paragraph.

\n" + self.assert_conversion(markdown_text, expected_html) + + def test_bold_and_italic_conversion(self): + markdown_text = "**Bold** and *Italic*" + expected_html = "

Bold and Italic

\n" + self.assert_conversion(markdown_text, expected_html) + + def test_list_conversion(self): + markdown_text = """ + - Item 1 + - Item 2 + - Item 3 + """ + expected_html = """ + \n + """ + self.assert_conversion(markdown_text, expected_html) + + def test_code_block_conversion(self): + markdown_text = """ + +```python\nprint('Hello, World!')\n +```" +expected_html = ''' +
print('Hello, World!')
+        
\n + """ # 注意:实际输出可能包含额外的空白或换行符,这取决于markdown库的处理方式 + self.assert_conversion(markdown_text, expected_html) + + +def test_link_conversion(self): + markdown_text = "[Google](https://www.google.com)" + expected_html = '

Google

\n' + self.assert_conversion(markdown_text, expected_html) + + +def test_image_conversion(self): + markdown_text = "![Alt Text](https://www.example.com/image.jpg)" + expected_html = '

Alt Text

\n' + self.assert_conversion(markdown_text, expected_html) + + +def test_blockquote_conversion(self): + markdown_text = "> This is a quote." + expected_html = '
\n

This is a quote.

\n
\n' + self.assert_conversion(markdown_text, expected_html) + + +def assert_conversion(self, markdown_text, expected_html): + converted_html = convert_markdown_to_html(markdown_text) + # 使用replace方法去除不必要的空白字符,以便更灵活地比较输出 + self.assertEqual(converted_html.replace('\n', '').replace('\r', ''), + expected_html.replace('\n', '').replace('\r', '')) + + +if __name__ == '__main__': + unittest.main()