summaryrefslogtreecommitdiff
path: root/html2text2.py
diff options
context:
space:
mode:
authorMatthew Fennell <matthew@fennell.dev>2026-08-23 22:39:35 +0100
committerMatthew Fennell <matthew@fennell.dev>2026-08-23 22:39:35 +0100
commit58b762a53a5e64d6a6ea6999009d1899f7b6a4da (patch)
tree950612344353c79d069b2f2185c8613c14ce7179 /html2text2.py
parent77078787b2568d791a0f180737d14070be46f23c (diff)
Add RSS feed plugins
These are used to save each feed entry to a file.
Diffstat (limited to 'html2text2.py')
-rw-r--r--html2text2.py29
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)