refactor: converted to block token

This commit is contained in:
Prof. Dr. Matthias Jung DL9MJ
2025-06-24 22:04:42 +02:00
committed by Tim Grelka
parent 059ed59eaf
commit c2209c5cc2
3 changed files with 18 additions and 7 deletions
+1 -1
View File
@@ -238,4 +238,4 @@ class FiftyOhmHtmlRenderer(HtmlRenderer):
return table
def render_include(self, token):
return self.include_handler(token.content)
return self.include_handler(token.ident)
+16 -5
View File
@@ -1,13 +1,24 @@
import re
from mistletoe.span_token import SpanToken
from mistletoe.block_token import BlockToken
class Include(SpanToken):
class Include(BlockToken):
"""
Span token ("[include:ident]").
Block token ("[include:ident]").
Includes raw html or javascript code from a file with the given identifier.
"""
parse_inner = False
pattern = re.compile(r'\[include:\s*([^\]]+)\]')
@staticmethod
def start(line):
return re.match(r"^\s*\[include:\s*[^\]]+\]", line)
@classmethod
def read(cls, lines):
re.compile(r'')
line = next(lines) # Consume the line with the include directive
ident = re.match(r"^\s*\[include:\s*([^\]]+)\]", line).group(1)
return ident
def __init__(self, match):
self.ident = match
+1 -1
View File
@@ -7,7 +7,7 @@ from renderer.fifty_ohm_html_renderer import FiftyOhmHtmlRenderer
@pytest.mark.html
def test_include_html():
assertions = {
'[include:ident]': "<p>ident</p>\n",
'[include:ident]': "ident\n",
}
def test_function(input):