From 81a5c6d3040d0f356932466085f1bd48e86a84aa Mon Sep 17 00:00:00 2001 From: Greenscreener Date: Sun, 20 Aug 2023 14:06:21 +0200 Subject: [PATCH] =?UTF-8?q?=20Include=20p=C5=99=C3=ADmo=20TeXov=C3=BDch=20?= =?UTF-8?q?a=20HTML=20soubor=C5=AF.=20Resolve=20#25?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/formatitko/transform_processor.py | 22 +++++++++++++--------- test/test.md | 3 +++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/formatitko/transform_processor.py b/src/formatitko/transform_processor.py index a6eb4b0..2c21e5e 100644 --- a/src/formatitko/transform_processor.py +++ b/src/formatitko/transform_processor.py @@ -368,7 +368,7 @@ class TransformProcessor: else: return BlockGroup(*content, context=new_context) - def transform_Div(self, e: Div) -> Union[Div, Group, Null]: + def transform_Div(self, e: Div) -> Union[Div, Group, Null, RawBlock]: e.content = self.transform(e.content) if "group" in e.classes: @@ -389,6 +389,8 @@ class TransformProcessor: if "partial" in e.attributes: # `partial` attribute # Used to include a file which is executed in a different (child) Context. + if not "type" in e.attributes: + e.attributes["type"] = "md" if not self.context.trusted: # If we're in an untrusted context, we shouldn't allow inclusion of files outside the PWD. full_path = os.path.abspath(self.context.dir + "/" + e.attributes["partial"]) pwd = os.path.abspath(".") @@ -396,13 +398,16 @@ class TransformProcessor: return nullify(e) text = open(self.context.dir + "/" + e.attributes["partial"], "r").read() path = self.context.dir + "/" + e.attributes["partial"] - includedDoc = import_md(text) - trusted = True - if "untrusted" in e.attributes and (e.attributes["untrusted"] == True or e.attributes["untrusted"] == 'True'): - trusted = False - if not self.context.trusted: - trusted = False - return self.create_Group(*includedDoc.content, new_context=Context(includedDoc, path, self.context, trusted=trusted)) + if e.attributes["type"] == "md": + includedDoc = import_md(text) + trusted = True + if "untrusted" in e.attributes and (e.attributes["untrusted"] == True or e.attributes["untrusted"] == 'True'): + trusted = False + if not self.context.trusted: + trusted = False + return self.create_Group(*includedDoc.content, new_context=Context(includedDoc, path, self.context, trusted=trusted)) + elif e.attributes["type"] in ["tex", "html"]: + return RawBlock(text, e.attributes["type"]) if "lang" in e.attributes: warnings.warn("To set language in a way formátítko will understand, this Div has to have the `.group` class and be a Group.", UserWarning) @@ -412,7 +417,6 @@ class TransformProcessor: def transform_Span(self, e: Span) -> Span: e.content = self.transform(e.content) - # TODO: This sadly doesn't work. We would need to create a separate class InlineGroup, that would be Inline. if "group" in e.classes: # `.group` class for Spans # Content of Span is enclosed in a separate context, all attributes are passed as metadata diff --git a/test/test.md b/test/test.md index 7f1eb8d..58aeb70 100644 --- a/test/test.md +++ b/test/test.md @@ -4,6 +4,9 @@ subtitle: 'A subtitle' are_we_there_yet: False lang: "en" --- +::: {partial="test-top.html" type="html"} +::: + [#test-files/test-import.md]{type=md} # Hello world!