blob: cd6e635b2b7a4fb866647d88cd49b14cf9a456c5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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)
|