From 3626585cbe41b27037ce300d0351a47f9ead7078 Mon Sep 17 00:00:00 2001 From: mar77i Date: Tue, 18 Mar 2025 18:23:49 +0100 Subject: [PATCH] break out tag introduction to separate method. simplify --- md.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/md.py b/md.py index cd45a2b..4e8fda1 100644 --- 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): -- 2.51.0