Skip to content

Commit

Permalink
Merge pull request #482 from PlaidWeb/feature/478-table-summary
Browse files Browse the repository at this point in the history
Properly strip tables when extracting an entry summary
  • Loading branch information
fluffy-critter authored Mar 20, 2022
2 parents 83f86f5 + 2e8e765 commit 774ecc6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
10 changes: 8 additions & 2 deletions publ/html_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ def __init__(self):
self._tag_stack = []

def handle_starttag(self, tag, attrs):
if tag.lower() == 'table':
self._consume = False

if tag.lower() == 'p':
if self._found:
self._consume = False
Expand All @@ -219,6 +222,10 @@ def handle_endtag(self, tag):

if self._consume:
self.append(f'</{tag}>')

if tag.lower() == 'table' and not self._found:
self._consume = True

if (not self._tag_stack or tag.lower() == 'p') and self._found:
self._consume = False

Expand All @@ -227,9 +234,8 @@ def handle_startendtag(self, tag, attrs):
self.append(utils.make_tag(tag, attrs, True))

def handle_data(self, data):
if data.strip():
if self._consume and data.strip():
self._found = True
if self._consume:
self.append(data)


Expand Down
2 changes: 1 addition & 1 deletion publ/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
'del', 'add', 'mark')

# Remove these tags from plaintext-style conversions
PLAINTEXT_REMOVE_ELEMENTS = ('del', 's')
PLAINTEXT_REMOVE_ELEMENTS = ('del', 's', 'table')


class ItemCounter(misaka.BaseRenderer):
Expand Down
20 changes: 20 additions & 0 deletions tests/content/cards/table in summary paragraph.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Title: Table in summary paragraph
Date: 2022-03-20 12:34:00-07:00
Entry-ID: 1711
UUID: e5fe5b31-039a-5838-b481-bde0001e28e1

| Name | Value |
|------|-------|
| foo | 1 |
| bar | 2 |
| baz | 3 |

This entry starts with a table. This paragraph should be the summary.

| Name | Value |
|------|-------|
| foo | 1 |
| bar | 2 |
| baz | 3 |

This second paragraph shouldn't appear in the summary.

0 comments on commit 774ecc6

Please sign in to comment.