feature: First tag implementation

This commit is contained in:
Prof. Dr. Matthias Jung DL9MJ
2024-12-07 20:20:49 +01:00
parent fbb26a8dd1
commit 2b05db77a4
3 changed files with 48 additions and 2 deletions
+27
View File
@@ -0,0 +1,27 @@
import re
from mistletoe.block_token import BlockToken, tokenize
class Tag(BlockToken):
@staticmethod
def start(line):
return re.match(r"^\s*<[^>]+>", line)
@classmethod
def read(cls, lines):
child_lines = []
first_line = next(lines)
tagtype = re.match(r"^\s*<([^>]+)>", first_line).group(1)
for line in lines:
if line.startswith(f"</{tagtype}>"):
break
else :
child_lines.append(line)
return tagtype, tokenize(child_lines)
def __init__(self, match):
self.tagtype, self.children = match