diff options
Diffstat (limited to 'html2text2.py')
| -rw-r--r-- | html2text2.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/html2text2.py b/html2text2.py new file mode 100644 index 0000000..cd6e635 --- /dev/null +++ b/html2text2.py @@ -0,0 +1,29 @@ +# SPDX-FileCopyrightText: 2026 Matthew Fennell <matthew@fennell.dev> +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +from __future__ import absolute_import, division, print_function + +import html2text + +class filter(object): + + def __init__(self, *args, feed=None, item=None, **kwargs): + if item.get('content'): + item['content_plain'] = ''.join([self.parse(x.value) + for x in item.get('content')]) + elif item.get('description') and item.get('description').strip(): + item['content_plain'] = self.parse(item.get('description')) + + @staticmethod + def parse(html=None): + if html is None: + return None + text_maker = html2text.HTML2Text() + text_maker.inline_links = False + text_maker.images_to_alt = True + text_maker.unicode_snob = True + text_maker.links_each_paragraph = True + text_maker.protect_links = True + text_maker.wrap_links = False + return text_maker.handle(html) |
