From 62043b2bafbcb57beae7559235bd6984b6275b55 Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Sun, 31 Dec 2023 11:05:59 -0800 Subject: [PATCH] Strip links from meta fields This gives us the flexibility to process non-flat URLs, which is useful for shorter feedback cycles during development. --- glowfic.py | 18 +++++++++++++++--- glowfic_test.py | 4 ++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/glowfic.py b/glowfic.py index 065c715..8561cd7 100644 --- a/glowfic.py +++ b/glowfic.py @@ -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) diff --git a/glowfic_test.py b/glowfic_test.py index 9b802c1..2d01c2a 100644 --- a/glowfic_test.py +++ b/glowfic_test.py @@ -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), '

') + self.assertEqual( + PandocTexifier("pandoc").texify(c.character), b'{Keltham}\n') + if __name__ == '__main__': unittest.main() -- 2.50.1