66from mdformat .renderer .typing import Postprocess , Render
77from wcwidth import wcswidth
88
9- _COMPACT_TABLES = False
10- """user-specified flag for toggling compact tables."""
11-
129
1310def 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
3024def _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
7771def _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