Skip to content

Commit

Permalink
Remove global variable
Browse files Browse the repository at this point in the history
  • Loading branch information
hukkin committed Oct 22, 2024
1 parent 17e7913 commit e7a5a08
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions mdformat_tables/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
from mdformat.renderer.typing import Postprocess, Render
from wcwidth import wcswidth

_COMPACT_TABLES = False
"""user-specified flag for toggling compact tables."""


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

global _COMPACT_TABLES
_COMPACT_TABLES = mdit.options["mdformat"].get("compact_tables", False)


def _lpad(text: str, width: int) -> str:
indent = width - wcswidth(text)
Expand Down Expand Up @@ -98,7 +92,7 @@ def _render_table(node: RenderTreeNode, context: RenderContext) -> str:

def _calculate_width(col_idx: int) -> int:
"""Work out the widths for each column."""
if _COMPACT_TABLES:
if context.options["mdformat"].get("compact_tables", False):
return 0
return max(3, *(wcswidth(row[col_idx]) for row in rows))

Expand Down

0 comments on commit e7a5a08

Please sign in to comment.