Whole file
didix21/mdutils
The author described this change as “Fix #42 Default table's text_align should be '---'”. It counts as a record because the check below fails on the code as it stood at b9c958631 and passes on c11571ea1, with nothing else changed between the two runs.
Projectdidix21/mdutils
Fix saved2020-09-12
Sharing licenceMIT · LICENSE.txt
Change size+12 −7
What the code was meant to do, written into the code itself as a save note
Fix #42 Default table's text_align should be '---'
The change
| 5 | 5 | # This file is part of mdutils. https://github.com/didix21/mdutils | |
| 6 | 6 | # | |
| 7 | 7 | # MIT License: (C) 2020 Dídac Coll | |
| 8 | + | from typing import Optional | |
| 8 | 9 | ||
| 9 | 10 | ||
| 10 | 11 | class Table: | |
| ⋯ | |||
| 14 | 15 | self.columns = 0 | |
| 15 | 16 | ||
| 16 | 17 | @staticmethod | |
| 17 | - | def _align(columns, text_align): | |
| 18 | + | def _align(columns, text_align: Optional[str] = None) -> str: | |
| 18 | 19 | """ This private method it's in charge of aligning text of a table. | |
| 19 | 20 | ||
| 20 | 21 | - notes: more information about `text_align` | |
| ⋯ | |||
| 44 | 45 | ||
| 45 | 46 | column_align_string = '|' + ''.join([' ---: |' for _ in range(columns)]) | |
| 46 | 47 | ||
| 48 | + | elif text_align is None: | |
| 49 | + | ||
| 50 | + | column_align_string = '|' + ''.join([' --- |' for _ in range(columns)]) | |
| 51 | + | ||
| 47 | 52 | return column_align_string | |
| 48 | 53 | ||
| 49 | - | def create_table(self, columns, rows, text, text_align='center'): | |
| 54 | + | def create_table(self, columns: int, rows: int, text: [str], text_align: Optional[str] = None): | |
| 50 | 55 | """This method takes a list of strings and creates a table. | |
| 51 | 56 | ||
| 52 | 57 | Using arguments ``columns`` and ``rows`` allows to create a table of *n* columns and *m* rows. | |
| ⋯ | |||
| 83 | 88 | column_align_string = self._align(columns, text_align) | |
| 84 | 89 | index = 0 | |
| 85 | 90 | if columns * rows == len(text): | |
| 86 | - | if text_align.lower() in ('right', 'center', 'left'): | |
| 87 | - | for r in range(rows + 1): | |
| 88 | - | if r == 1: | |
| 91 | + | if text_align is None or text_align.lower() in ('right', 'center', 'left'): | |
| 92 | + | for row in range(rows + 1): | |
| 93 | + | if row == 1: | |
| 89 | 94 | table += column_align_string # Row align, Example: '| :---: | :---: | ... | \n' | |
| 90 | 95 | else: | |
| 91 | 96 | table += '|' | |
| 92 | - | for c in range(columns): | |
| 97 | + | for _ in range(columns): | |
| 93 | 98 | table += text[index] + '|' | |
| 94 | 99 | index += 1 | |
| 95 | 100 | ||
| ⋯ | |||
| 98 | 103 | return table | |
| 99 | 104 | ||
| 100 | 105 | else: | |
| 101 | - | raise ValueError("text_align's expected value: 'right', 'center' or 'left', but text_align = " | |
| 106 | + | raise ValueError("text_align's expected value: 'right', 'center', 'left' or None , but text_align = " | |
| 102 | 107 | + text_align.lower()) | |
| 103 | 108 | else: | |
| 104 | 109 | raise ValueError("columns * rows is not equal to text length") | |
The check that tells the two apart
fail→pass·tests/test_tools/test_table.py::TestTable::test_create_default_table
Check file tests/test_tools/test_table.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before itb9c95863140901d29ffc9c2518fcdb27d7eb054f
Broken version dated2020-09-12
Modulemdutils.tools.Table
Units changedTable
Fingerprint831d7a145ac62154
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.
Other bugs found in didix21/mdutils
- 2025-10-18fix: Text starting with ** (bold) breaks new_list method
- 2022-10-27MarkDownFile
- 2021-06-07Fix #6: add option to wrap text on new lines, paragraphs and writes
- 2020-06-19MarkDownFile