]> git.scottworley.com Git - paperdoorknob/commitdiff
Strip links from meta fields
authorScott Worley <scottworley@scottworley.com>
Sun, 31 Dec 2023 19:05:59 +0000 (11:05 -0800)
committerScott Worley <scottworley@scottworley.com>
Sun, 31 Dec 2023 19:05:59 +0000 (11:05 -0800)
This gives us the flexibility to process non-flat URLs, which is useful
for shorter feedback cycles during development.

glowfic.py
glowfic_test.py

index 065c71523cb1ae71b1b3da0dc9686c6ce540fc0e..8561cd756236bc1c5bf37c2b913ac91fad0b6a77 100644 (file)
@@ -89,13 +89,25 @@ def makeChunk(chunk_dom: Tag, image_store: ImageStore) -> Chunk:
         assert tag is None or isinstance(tag, Tag)
         return tag
 
+    def stripHREF(tag: Tag) -> None:
+        for c in tag.findChildren("a"):
+            if "href" in c.attrs:
+                del c.attrs["href"]
+
+    def getMeta(css_class: str) -> Tag | None:
+        tag = getByClass(css_class)
+        if tag is None:
+            return None
+        stripHREF(tag)
+        return tag
+
     content = chunk_dom.findChild('div', class_='post-content')
     assert isinstance(content, Tag)
 
     return Chunk(getIcon(),
-                 getByClass('post-character'),
-                 getByClass('post-screenname'),
-                 getByClass('post-author'),
+                 getMeta('post-character'),
+                 getMeta('post-screenname'),
+                 getMeta('post-author'),
                  content)
 
 
index 9b802c180cf3463e659f892948b0c9a64d4f936e..2d01c2a7e85b2d272fb60ed4dafcb657be72440e 100644 (file)
@@ -11,6 +11,7 @@ from bs4 import BeautifulSoup
 
 from images import FakeImageStore
 from glowfic import chunkDOMs, makeChunk
+from texify import PandocTexifier
 
 
 class TestSplit(unittest.TestCase):
@@ -67,6 +68,9 @@ class TestMakeChunk(unittest.TestCase):
         self.assertEqual(str(c.content),
                          '<div class="post-content"><p></p></div>')
 
+        self.assertEqual(
+            PandocTexifier("pandoc").texify(c.character), b'{Keltham}\n')
+
 
 if __name__ == '__main__':
     unittest.main()