diff options
author | Waylan Limberg <waylan.limberg@icloud.com> | 2020-06-29 15:43:30 -0400 |
---|---|---|
committer | Waylan Limberg <waylan.limberg@icloud.com> | 2020-06-30 14:36:01 -0400 |
commit | 2164c4b4752b9061c742326ea0413719333058fc (patch) | |
tree | 7a27da2eb6eac66d0ccb1349e42b5975cb8d4c8a | |
parent | 706d1fd096a49df0662a181f9dae726edefff43f (diff) | |
download | python-markdown-2164c4b4752b9061c742326ea0413719333058fc.tar.gz |
Add suport for attr_lists in table headers.
-rw-r--r-- | docs/change_log/release-3.3.md | 3 | ||||
-rw-r--r-- | docs/extensions/attr_list.md | 2 | ||||
-rw-r--r-- | markdown/extensions/attr_list.py | 2 | ||||
-rw-r--r-- | tests/test_syntax/extensions/test_attr_list.py | 20 |
4 files changed, 20 insertions, 7 deletions
diff --git a/docs/change_log/release-3.3.md b/docs/change_log/release-3.3.md index f826082..0e0bb89 100644 --- a/docs/change_log/release-3.3.md +++ b/docs/change_log/release-3.3.md @@ -43,6 +43,9 @@ be separated from the rest of the content by at least one space. This makes it e lists defined on inline elements within a cell and the attribute list for the cell itself. It is also more consistent with how attribute lists are defined on other types of elements. +The extension has also added support for defining attribute lists on table header cells (`<th>` elements) in the same +manner as data cells (`<td>` elements). + In addition, the documentation for the extensions received an overhaul. The features (#987) and limitations (#965) of the extension are now fully documented. ## New features diff --git a/docs/extensions/attr_list.md b/docs/extensions/attr_list.md index d9f4d68..d3d5e12 100644 --- a/docs/extensions/attr_list.md +++ b/docs/extensions/attr_list.md @@ -156,6 +156,8 @@ Note that in the first column, the attribute list is preceded by a space; theref (`<td>` element). However, in the second column, the attribute list is not preceded by a space; therefore, it is assigned to the inline element (`<em>`) which immediately preceded it. +Attribute lists may also be defined on table header cells (`<th>` elements) in the same manner. + ### Limitations There are a few types of elements which attribute lists do not work with. As a reminder, Markdown is a subset of HTML diff --git a/markdown/extensions/attr_list.py b/markdown/extensions/attr_list.py index d02194e..9a67551 100644 --- a/markdown/extensions/attr_list.py +++ b/markdown/extensions/attr_list.py @@ -79,7 +79,7 @@ class AttrListTreeprocessor(Treeprocessor): if self.md.is_block_level(elem.tag): # Block level: check for attrs on last line of text RE = self.BLOCK_RE - if isheader(elem) or elem.tag in ['dt', 'td']: + if isheader(elem) or elem.tag in ['dt', 'td', 'th']: # header, def-term, or table cell: check for attrs at end of element RE = self.HEADER_RE if len(elem) and elem.tag == 'li': diff --git a/tests/test_syntax/extensions/test_attr_list.py b/tests/test_syntax/extensions/test_attr_list.py index 3d65761..6baaafb 100644 --- a/tests/test_syntax/extensions/test_attr_list.py +++ b/tests/test_syntax/extensions/test_attr_list.py @@ -39,9 +39,10 @@ class TestAttrList(TestCase): self.assertMarkdownRenders( self.dedent( """ - | valid on td | inline | empty | missing space | not at end | + | A { .foo } | *B*{ .foo } | C { } | D{ .foo } | E { .foo } F | |-------------|-------------|-------|---------------|--------------| | a { .foo } | *b*{ .foo } | c { } | d{ .foo } | e { .foo } f | + | valid on td | inline | empty | missing space | not at end | """ ), self.dedent( @@ -49,11 +50,11 @@ class TestAttrList(TestCase): <table> <thead> <tr> - <th>valid on td</th> - <th>inline</th> - <th>empty</th> - <th>missing space</th> - <th>not at end</th> + <th class="foo">A</th> + <th><em class="foo">B</em></th> + <th>C { }</th> + <th>D{ .foo }</th> + <th>E { .foo } F</th> </tr> </thead> <tbody> @@ -64,6 +65,13 @@ class TestAttrList(TestCase): <td>d{ .foo }</td> <td>e { .foo } f</td> </tr> + <tr> + <td>valid on td</td> + <td>inline</td> + <td>empty</td> + <td>missing space</td> + <td>not at end</td> + </tr> </tbody> </table> """ |