]> git.scottworley.com Git - paperdoorknob/commitdiff
Support strikethrough
authorScott Worley <scottworley@scottworley.com>
Fri, 29 Dec 2023 19:46:36 +0000 (11:46 -0800)
committerScott Worley <scottworley@scottworley.com>
Fri, 29 Dec 2023 19:46:36 +0000 (11:46 -0800)
domfilter.py
domfilter_test.py
paperdoorknob.py

index 22f96a13b23c51c02229b5a3eaf5740d37bf8303..e1095f0f856842d3d8fa9819dd36d57c4d1fda92 100644 (file)
@@ -10,9 +10,16 @@ from typing import Any, Callable, List, Tuple
 from bs4.element import Tag
 
 
 from bs4.element import Tag
 
 
+def _changeTag(tag: Tag, new_name: str) -> Tag:
+    tag.name = new_name
+    return tag
+
+
 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")]),
 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;")]),
 ]
 
 
 ]
 
 
index c3c8ee2936b3a88b21739a6afc8832a41ac6766a..8daca20685dd0ba3ed04b3b1a82e9135ff42b9f3 100644 (file)
@@ -21,6 +21,11 @@ class TestDOMFilters(unittest.TestCase):
               This is glowfic
               <div class="post-footer">This is the footer</div>
             </div>''', 'html.parser')
               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)
 
     def testStripFooters(self) -> None:
         ApplyDOMFilters("NoFooter", self._html)
@@ -37,6 +42,13 @@ class TestDOMFilters(unittest.TestCase):
         self.assertEqual(list(self._html.stripped_strings),
                          ["This is glowfic"])
 
         self.assertEqual(list(self._html.stripped_strings),
                          ["This is glowfic"])
 
+    def testStrike(self) -> None:
+        ApplyDOMFilters('Strike', self._strike)
+        s = self._strike.find_all('s')
+        self.assertEqual(len(s), 1)
+        self.assertEqual(list(s[0].stripped_strings),
+                         ['Abandon hope and endure.'])
+
 
 if __name__ == '__main__':
     unittest.main()
 
 if __name__ == '__main__':
     unittest.main()
index b364f4d63653d3fa486ca764bb60768967b60763..0da6d97c8626938e29c407dd507467897994c9ea 100644 (file)
@@ -21,6 +21,7 @@ def process(spec: Spec) -> None:
 \\usepackage{booktabs}
 \\usepackage{graphicx}
 \\usepackage{longtable}
 \\usepackage{booktabs}
 \\usepackage{graphicx}
 \\usepackage{longtable}
+\\usepackage{soul}
 \\usepackage{varwidth}
 \\usepackage{wrapstuff}
 ''')
 \\usepackage{varwidth}
 \\usepackage{wrapstuff}
 ''')