refactor: converted to block token
This commit is contained in:
@@ -238,4 +238,4 @@ class FiftyOhmHtmlRenderer(HtmlRenderer):
|
|||||||
return table
|
return table
|
||||||
|
|
||||||
def render_include(self, token):
|
def render_include(self, token):
|
||||||
return self.include_handler(token.content)
|
return self.include_handler(token.ident)
|
||||||
|
|||||||
+16
-5
@@ -1,13 +1,24 @@
|
|||||||
import re
|
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.
|
Includes raw html or javascript code from a file with the given identifier.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
parse_inner = False
|
@staticmethod
|
||||||
pattern = re.compile(r'\[include:\s*([^\]]+)\]')
|
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
|
||||||
@@ -7,7 +7,7 @@ from renderer.fifty_ohm_html_renderer import FiftyOhmHtmlRenderer
|
|||||||
@pytest.mark.html
|
@pytest.mark.html
|
||||||
def test_include_html():
|
def test_include_html():
|
||||||
assertions = {
|
assertions = {
|
||||||
'[include:ident]': "<p>ident</p>\n",
|
'[include:ident]': "ident\n",
|
||||||
}
|
}
|
||||||
|
|
||||||
def test_function(input):
|
def test_function(input):
|
||||||
|
|||||||
Reference in New Issue
Block a user