Skip to content

Commit

Permalink
Merge pull request #296 from hugovk/fix-narrow-markdown-columns
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Apr 9, 2024
2 parents 1f156f8 + fd24cf6 commit 2702d6b
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 124 deletions.
11 changes: 11 additions & 0 deletions src/prettytable/prettytable.py
Expand Up @@ -135,6 +135,7 @@ def __init__(self, field_names=None, **kwargs) -> None:
self.int_format = {}
self.float_format = {}
self.custom_format = {}
self._style = None

if field_names:
self.field_names = field_names
Expand Down Expand Up @@ -1270,6 +1271,7 @@ def _get_options(self, kwargs):
##############################

def set_style(self, style) -> None:
self._style = style
if style == DEFAULT:
self._set_default_style()
elif style == MSWORD_FRIENDLY:
Expand Down Expand Up @@ -1593,6 +1595,15 @@ def _compute_widths(self, rows, options) -> None:
widths[index] = max(widths[index], _get_size(value)[0])
if fieldname in self.min_width:
widths[index] = max(widths[index], self.min_width[fieldname])

if self._style == MARKDOWN:
# Markdown needs at least one hyphen in the divider
if self._align[fieldname] in ("l", "r"):
min_width = 1
else: # "c"
min_width = 3
widths[index] = max(min_width, widths[index])

self._widths = widths

per_col_padding = sum(self._get_padding_widths(options))
Expand Down

0 comments on commit 2702d6b

Please sign in to comment.