From c2209c5cc26cae10271faff2e7ea57f58e9dd8ec Mon Sep 17 00:00:00 2001 From: "Prof. Dr. Matthias Jung DL9MJ" Date: Mon, 2 Jun 2025 21:47:32 +0200 Subject: [PATCH] refactor: converted to block token --- renderer/fifty_ohm_html_renderer.py | 2 +- renderer/include.py | 21 ++++++++++++++++----- test/test_include.py | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/renderer/fifty_ohm_html_renderer.py b/renderer/fifty_ohm_html_renderer.py index 9e34035..e0d73b7 100644 --- a/renderer/fifty_ohm_html_renderer.py +++ b/renderer/fifty_ohm_html_renderer.py @@ -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) diff --git a/renderer/include.py b/renderer/include.py index 5b96f02..9f2a690 100644 --- a/renderer/include.py +++ b/renderer/include.py @@ -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 \ No newline at end of file diff --git a/test/test_include.py b/test/test_include.py index e8a9dfb..24c02f7 100644 --- a/test/test_include.py +++ b/test/test_include.py @@ -7,7 +7,7 @@ from renderer.fifty_ohm_html_renderer import FiftyOhmHtmlRenderer @pytest.mark.html def test_include_html(): assertions = { - '[include:ident]': "

ident

\n", + '[include:ident]': "ident\n", } def test_function(input):