forked from CelsiaSolaraStarflare/Arcana
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_markdown_parser.py
More file actions
81 lines (59 loc) · 1.92 KB
/
test_markdown_parser.py
File metadata and controls
81 lines (59 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python3
"""
Test script for the markdown parser functionality in mixup.py
"""
import os
import sys
sys.path.append(os.path.dirname(__file__))
from docx import Document
from mixup import parse_markdown_content_to_word, parse_markdown_to_word_runs
def test_markdown_parser():
"""Test the markdown parser with sample content."""
# Create a new document
doc = Document()
# Test markdown content
test_content = """
# Main Header
This is a paragraph with **bold text**, *italic text*, and `code text`.
## Section Header
Here's a list:
- First item with **bold**
- Second item with *italic*
- Third item with `code`
### Subsection
1. Numbered list item one
2. Item with [a link](https://example.com)
3. Final numbered item
> This is a blockquote with important information.
Here's some `inline code` and more **bold** text.
---
## Code Block Example
```python
def hello_world():
print("Hello, World!")
```
That was a code block.
"""
# Parse the markdown content
print("🧪 Testing markdown parser...")
parse_markdown_content_to_word(doc, test_content)
# Save test document
test_file = "test_markdown_output.docx"
doc.save(test_file)
print(f"✅ Test document saved as: {test_file}")
# Test individual run parsing
print("🧪 Testing markdown run parser...")
test_para = doc.add_paragraph()
test_text = "This has **bold**, *italic*, `code`, and [link](https://example.com) formatting."
parse_markdown_to_word_runs(test_para, test_text)
doc.save(test_file)
print(f"✅ Updated test document with run parsing test")
return test_file
if __name__ == "__main__":
try:
test_file = test_markdown_parser()
print(f"\n🎉 Markdown parser test completed successfully!")
print(f"📄 Check the generated file: {test_file}")
except Exception as e:
print(f"❌ Test failed: {e}")
sys.exit(1)