DOMFilters: List[Tuple[str, Callable[[Tag], Any]]] = [
- ("NoEdit", lambda x: [eb.decompose() for eb in x.find_all("div", class_="post-edit-box")]),
- ("NoFooter", lambda x: [foot.decompose() for foot in x.find_all("div", class_="post-footer")]),
("Strike", lambda x: [_changeTag(span, 's')
for span in x.find_all("span", style="text-decoration: line-through;")]),
]
class TestDOMFilters(unittest.TestCase):
def setUp(self) -> None:
- self._html = BeautifulSoup(b'''
- <div class="post-container post-post">
- <div class="post-edit-box">This is the edit box</div>
- This is glowfic
- <div class="post-footer">This is the footer</div>
- </div>''', 'html.parser')
self._strike = BeautifulSoup(b'''
<div class="post-content">
<p><span style="text-decoration: line-through;">Abandon hope and endure.</span></p>
<p>No. Win.</p>
</div>''', 'html.parser')
- def testStripFooters(self) -> None:
- ApplyDOMFilters("NoFooter", self._html)
- self.assertEqual(list(self._html.stripped_strings),
- ["This is the edit box", "This is glowfic"])
-
- def testStripEditBoxes(self) -> None:
- ApplyDOMFilters("NoEdit", self._html)
- self.assertEqual(list(self._html.stripped_strings),
- ["This is glowfic", "This is the footer"])
-
- def testStripFootersAndEditBoxes(self) -> None:
- ApplyDOMFilters("NoEdit,NoFooter", self._html)
- self.assertEqual(list(self._html.stripped_strings),
- ["This is glowfic"])
-
def testStrike(self) -> None:
ApplyDOMFilters('Strike', self._strike)
s = self._strike.find_all('s')
import paperdoorknob
from testing.fakeserver import FakeGlowficServer
-from domfilter import ApplyDOMFilters
from fetch import DirectFetcher, FakeFetcher, Fetcher
from glowfic import ContentOnlyLayout, BelowIconLayout
from images import FakeImageStore
self.fetcher(),
FakeImageStore(),
lambda x: x,
- lambda x: ApplyDOMFilters('NoEdit,NoFooter', x),
+ lambda x: None,
lambda x: x,
ContentOnlyLayout(PandocTexifier('pandoc')),
'margin=20mm',
self.fetcher(),
FakeImageStore(),
lambda x: x,
- lambda x: ApplyDOMFilters('NoEdit,NoFooter', x),
+ lambda x: None,
lambda x: x,
ContentOnlyLayout(texifier),
None,
self.fetcher(),
FakeImageStore(),
lambda x: x,
- lambda x: ApplyDOMFilters('NoEdit,NoFooter', x),
+ lambda x: None,
lambda x: x,
BelowIconLayout(PandocTexifier('pandoc'), 20),
None,