]> git.mar77i.info Git - mar77i.info/commitdiff
break out tag introduction to separate method. simplify
authormar77i <mar77i@protonmail.ch>
Tue, 18 Mar 2025 17:23:49 +0000 (18:23 +0100)
committermar77i <mar77i@protonmail.ch>
Tue, 18 Mar 2025 17:23:49 +0000 (18:23 +0100)
md.py

diff --git a/md.py b/md.py
index cd45a2b93b49020d8b648482b3271efbfd827c7e..4e8fda183774ac4c48f35cb64e7b3339ce4b59a1 100644 (file)
--- a/md.py
+++ b/md.py
@@ -119,6 +119,12 @@ class Paragraph:
             self.backslash = False
         return True
 
+    def handle_tag(self, c):
+        for tag_class in MDTag.registered_tags:
+            if c == tag_class.char and self.check_states(tag_class):
+                return tag_class(self.states, self.sio)
+        return None
+
     def join_lines(self):
         if self.sio.getvalue():
             assert not self.lines
@@ -130,17 +136,8 @@ class Paragraph:
             if c == "\\":
                 self.backslash = True
                 continue
-            tag = None
-            for tag_class in MDTag.registered_tags:
-                if c == tag_class.char and self.check_states(tag_class):
-                    tag = tag_class(self.states, self.sio)
-                    break
-            if tag is not None:
-                continue
-            if len(self.states) > 0:
-                self.states[-1].write(c)
-            else:
-                self.sio.write(c)
+            if not self.handle_tag(c):
+                (self.states[-1] if self.states else self.sio).write(c)
         assert len(self.states) == 0, self.states
         assert not self.backslash
         self.lines.clear()
@@ -169,7 +166,7 @@ class BulletList(Paragraph):
         return self.list_items[-1].lines
 
     @lines.setter
-    def lines(self, value):
+    def lines(self, _):
         self.list_items.append(self.ListItem())
 
     def join_lines(self):