diff options
| author | Gaige B Paulsen <github@gbp.gaige.net> | 2022-05-05 15:32:07 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-05 15:32:07 -0400 |
| commit | 659a43659c6012df8d8ceb4a3681d2ddb1cb7540 (patch) | |
| tree | 2f523c0b1de1a402141407ef80e22844c71a45c5 /markdown/extensions | |
| parent | db98a2632447387cd5c965b324904ee780809b81 (diff) | |
| download | python-markdown-659a43659c6012df8d8ceb4a3681d2ddb1cb7540.tar.gz | |
Update th/td to use style attribute
This allows better interoperation with CSS style sheets, as the align
object on the TH is skipped if the css uses 'text-align: inherit' and
the previous 'text-align' is used instead (or the default: left).
Added an override to restore the original `align` behavior
Moved existing tests to the new test infrastructure
Added new tests to test the configuration parameter
Updated documentation to document the configuration parameter.
Diffstat (limited to 'markdown/extensions')
| -rw-r--r-- | markdown/extensions/tables.py | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/markdown/extensions/tables.py b/markdown/extensions/tables.py index 0a9d084..c8b1024 100644 --- a/markdown/extensions/tables.py +++ b/markdown/extensions/tables.py @@ -30,9 +30,11 @@ class TableProcessor(BlockProcessor): RE_CODE_PIPES = re.compile(r'(?:(\\\\)|(\\`+)|(`+)|(\\\|)|(\|))') RE_END_BORDER = re.compile(r'(?<!\\)(?:\\\\)*\|$') - def __init__(self, parser): + def __init__(self, parser, config): self.border = False self.separator = '' + self.config = config + super().__init__(parser) def test(self, parent, block): @@ -126,7 +128,10 @@ class TableProcessor(BlockProcessor): except IndexError: # pragma: no cover c.text = "" if a: - c.set('align', a) + if self.config['use_align_attribute']: + c.set('align', a) + else: + c.set('style', f'text-align: {a};') def _split_row(self, row): """ split a row of text into list of cells. """ @@ -212,11 +217,19 @@ class TableProcessor(BlockProcessor): class TableExtension(Extension): """ Add tables to Markdown. """ + def __init__(self, **kwargs): + self.config = { + 'use_align_attribute': [False, 'True to use align attribute instead of style.'], + } + + super().__init__(**kwargs) + def extendMarkdown(self, md): """ Add an instance of TableProcessor to BlockParser. """ if '|' not in md.ESCAPED_CHARS: md.ESCAPED_CHARS.append('|') - md.parser.blockprocessors.register(TableProcessor(md.parser), 'table', 75) + processor = TableProcessor(md.parser, self.getConfigs()) + md.parser.blockprocessors.register(processor, 'table', 75) def makeExtension(**kwargs): # pragma: no cover |
