Files
50ohm/renderer/tag.py
T
Prof.Dr. Matthias Jung DL9MJ 77ba4d9217 Pull request #38: feature: person tag added
Merge in FRAG/50ohm.de from feature/person to main

* commit '3cc331f4f8da9327a8f97b7c28d956fd2b4e075c':
  feature: person tag added
2025-06-24 22:04:13 +02:00

45 lines
894 B
Python

import re
from mistletoe.block_token import BlockToken, tokenize
captures = [
"margin",
"indepth",
"webmargin",
"warning",
"attention",
"tip",
"webtip",
"webindepth",
"person",
"fullwidth",
"unit",
"danger",
"webonly",
"latexonly",
"wordorigin",
]
class Tag(BlockToken):
@staticmethod
def start(line):
return re.match(r"^\s*<(" + "|".join(captures) + r")+>", 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