28 lines
928 B
Python
28 lines
928 B
Python
import unittest
|
|
|
|
from app.features.memoir.markdown_sanitize import (
|
|
sanitize_story_for_chapter_compose,
|
|
strip_leading_heading_if_matches_title,
|
|
strip_markdown_tables,
|
|
)
|
|
|
|
|
|
class MarkdownSanitizeTest(unittest.TestCase):
|
|
def test_strip_table_block(self):
|
|
md = "第一段\n\n| a | b |\n| - | - |\n| 1 | 2 |\n\n第二段"
|
|
out = strip_markdown_tables(md)
|
|
self.assertNotIn("| a |", out)
|
|
self.assertIn("第一段", out)
|
|
self.assertIn("第二段", out)
|
|
|
|
def test_strip_heading_when_matches_title(self):
|
|
body = "## 童年\n\n正文"
|
|
out = strip_leading_heading_if_matches_title(body, "童年")
|
|
self.assertEqual(out, "正文")
|
|
|
|
def test_sanitize_compose(self):
|
|
raw = "| x | y |\n|---|---|\n|1|2|\n\n你好"
|
|
out = sanitize_story_for_chapter_compose(raw, "T")
|
|
self.assertIn("你好", out)
|
|
self.assertNotIn("| x |", out)
|