Skip to content
This repository was archived by the owner on Oct 16, 2025. It is now read-only.

Commit 42a8b08

Browse files
authored
🔧 Use new API to fix DeprecationWarning (#23)
1 parent 038e473 commit 42a8b08

File tree

4 files changed

+39
-8
lines changed

4 files changed

+39
-8
lines changed

‎mdformat_tables/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
from .plugin import ( # noqa: F401
66
POSTPROCESSORS,
77
RENDERERS,
8-
add_cli_options,
8+
add_cli_argument_group,
99
update_mdit,
1010
)

‎mdformat_tables/plugin.py‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
from wcwidth import wcswidth
88

99

10-
def add_cli_options(parser: argparse.ArgumentParser) -> None:
11-
"""Add options to the mdformat CLI, to be stored in `mdit.options["mdformat"]`."""
12-
parser.add_argument(
10+
def add_cli_argument_group(group: argparse._ArgumentGroup) -> None:
11+
"""Add options to the mdformat CLI, to be stored in
12+
`mdit.options["mdformat"]["plugin"]["tables"]`."""
13+
group.add_argument(
1314
"--compact-tables",
1415
action="store_true",
1516
help="If specified, do not add padding to table cells.",
@@ -70,7 +71,14 @@ def format_delimiter_cell(index: int, align: str) -> str:
7071

7172
def _render_table(node: RenderTreeNode, context: RenderContext) -> str:
7273
"""Render a `RenderTreeNode` of type "table"."""
73-
compact_tables = context.options["mdformat"].get("compact_tables", False)
74+
compact_tables_from_cli_or_toml = (
75+
context.options["mdformat"]
76+
.get("plugin", {})
77+
.get("tables", {})
78+
.get("compact_tables")
79+
)
80+
compact_tables_from_api = context.options["mdformat"].get("compact_tables")
81+
compact_tables = compact_tables_from_cli_or_toml or compact_tables_from_api
7482
# gather rendered cell content into row * column array
7583
rows: List[List[str]] = []
7684
align: List[List[str]] = []

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ classifiers = [
1717
keywords = "mdformat,markdown,markdown-it"
1818

1919
requires-python=">=3.9"
20-
requires=["mdformat>=0.7.5,<0.8.0", "wcwidth>=0.2.13"]
20+
requires=["mdformat>=0.7.19,<0.8.0", "wcwidth>=0.2.13"]
2121

2222
[tool.flit.metadata.requires-extra]
2323
test = [

‎tests/test_parse.py‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from markdown_it.utils import read_fixture_file
44
import mdformat
5+
import mdformat._cli
56
import pytest
67

78
FIXTURE_PATH = Path(__file__).parent / "fixtures.md"
@@ -11,22 +12,44 @@
1112
@pytest.mark.parametrize(
1213
"line,title,text,expected", fixtures, ids=[f[1] for f in fixtures]
1314
)
14-
def test_fixtures(line, title, text, expected):
15+
def test_fixtures__api(line, title, text, expected):
1516
output = mdformat.text(text, extensions={"tables"})
1617
print(output)
1718
assert output.rstrip() == expected.rstrip(), output
1819

1920

21+
@pytest.mark.parametrize(
22+
"line,title,text,expected", fixtures, ids=[f[1] for f in fixtures]
23+
)
24+
def test_fixtures__cli(line, title, text, expected, tmp_path):
25+
file_path = tmp_path / "test_markdown.md"
26+
file_path.write_text(text, encoding="utf-8")
27+
assert mdformat._cli.run([str(file_path)]) == 0
28+
md_new = file_path.read_text(encoding="utf-8")
29+
assert md_new == expected
30+
31+
2032
FIXTURES_COMPACT_PATH = Path(__file__).parent / "fixtures-compact.md"
2133
fixtures_compact = read_fixture_file(FIXTURES_COMPACT_PATH)
2234

2335

2436
@pytest.mark.parametrize(
2537
"line,title,text,expected", fixtures_compact, ids=[f[1] for f in fixtures_compact]
2638
)
27-
def test_fixtures_compact(line, title, text, expected):
39+
def test_fixtures_compact__api(line, title, text, expected):
2840
output = mdformat.text(
2941
text, extensions={"tables"}, options={"compact_tables": True}
3042
)
3143
print(output)
3244
assert output.rstrip() == expected.rstrip(), output
45+
46+
47+
@pytest.mark.parametrize(
48+
"line,title,text,expected", fixtures_compact, ids=[f[1] for f in fixtures_compact]
49+
)
50+
def test_fixtures_compact__cli(line, title, text, expected, tmp_path):
51+
file_path = tmp_path / "test_markdown.md"
52+
file_path.write_text(text, encoding="utf-8")
53+
assert mdformat._cli.run([str(file_path), "--compact-tables"]) == 0
54+
md_new = file_path.read_text(encoding="utf-8")
55+
assert md_new == expected

0 commit comments

Comments
 (0)