实现 ClinDB 第一批清洗组件

This commit is contained in:
2026-08-23 20:56:36 +08:00
parent 6fcc7d5736
commit 80001a8ab9
28 changed files with 2538 additions and 67 deletions
+63
View File
@@ -0,0 +1,63 @@
from __future__ import annotations
import pytest
from mdpolish import Pipeline, RunStatus
from mdpolish.components import HtmlTableLayoutComponent
TABLE = '<table class="x"><tr><td colspan="2">A</td></tr><tr><td>B</td><td>C</td></tr></table>'
def transform(markdown: str): # type: ignore[no-untyped-def]
return Pipeline([HtmlTableLayoutComponent()]).transform(markdown)
def test_expands_rows_without_changing_tags_attributes_or_cells() -> None:
result = transform(f"before\n{TABLE}\nafter")
assert result.status is RunStatus.SUCCESS
assert result.output_markdown == (
"before\n<table class=\"x\">\n"
" <tr><td colspan=\"2\">A</td></tr>\n"
" <tr><td>B</td><td>C</td></tr>\n"
"</table>\nafter"
)
assert len(result.changes) == 1
@pytest.mark.parametrize("line_ending", ["\n", "\r\n", "\r"])
def test_uses_the_documents_single_line_ending_style(line_ending: str) -> None:
markdown = f"before{line_ending}{TABLE}{line_ending}after"
result = transform(markdown)
assert result.output_markdown is not None
assert f"<table class=\"x\">{line_ending} <tr>" in result.output_markdown
def test_table_only_document_uses_lf() -> None:
assert transform(TABLE).output_markdown == (
'<table class="x">\n'
' <tr><td colspan="2">A</td></tr>\n'
" <tr><td>B</td><td>C</td></tr>\n"
"</table>"
)
@pytest.mark.parametrize(
"markdown",
[
"before\n<table><tr><td>A</td></tr>\r\nafter",
"<table>\n <tr><td>A</td></tr>\n</table>",
"<table><tr><td>A</tr></table>",
"<table><tbody><tr><td>A</td></tr></tbody></table>",
"<table><tr><td><em>A</em></td></tr></table>",
],
)
def test_mixed_multiline_or_non_strict_tables_are_preserved(markdown: str) -> None:
assert transform(markdown).output_markdown == markdown
def test_successful_output_is_idempotent() -> None:
pipeline = Pipeline([HtmlTableLayoutComponent()])
first = pipeline.transform(TABLE)
assert first.output_markdown is not None
assert pipeline.transform(first.output_markdown).changes == ()