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

Commit 01dbde1

Browse files
authored
🐛 Remove a global variable (#22)
1 parent 17e7913 commit 01dbde1

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

mdformat_tables/plugin.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
from mdformat.renderer.typing import Postprocess, Render
77
from wcwidth import wcswidth
88

9-
_COMPACT_TABLES = False
10-
"""user-specified flag for toggling compact tables."""
11-
129

1310
def add_cli_options(parser: argparse.ArgumentParser) -> None:
1411
"""Add options to the mdformat CLI, to be stored in `mdit.options["mdformat"]`."""
@@ -23,9 +20,6 @@ def update_mdit(mdit: MarkdownIt) -> None:
2320
"""Update the parser, e.g. by adding a plugin: `mdit.use(myplugin)`"""
2421
mdit.enable("table")
2522

26-
global _COMPACT_TABLES
27-
_COMPACT_TABLES = mdit.options["mdformat"].get("compact_tables", False)
28-
2923

3024
def _lpad(text: str, width: int) -> str:
3125
indent = width - wcswidth(text)
@@ -76,6 +70,7 @@ def format_delimiter_cell(index: int, align: str) -> str:
7670

7771
def _render_table(node: RenderTreeNode, context: RenderContext) -> str:
7872
"""Render a `RenderTreeNode` of type "table"."""
73+
compact_tables = context.options["mdformat"].get("compact_tables", False)
7974
# gather rendered cell content into row * column array
8075
rows: List[List[str]] = []
8176
align: List[List[str]] = []
@@ -98,7 +93,7 @@ def _render_table(node: RenderTreeNode, context: RenderContext) -> str:
9893

9994
def _calculate_width(col_idx: int) -> int:
10095
"""Work out the widths for each column."""
101-
if _COMPACT_TABLES:
96+
if compact_tables:
10297
return 0
10398
return max(3, *(wcswidth(row[col_idx]) for row in rows))
10499

0 commit comments

Comments
 (0)