Include přímo TeXových a HTML souborů. Resolve #25
This commit is contained in:
parent
10eda42638
commit
81a5c6d304
2 changed files with 16 additions and 9 deletions
|
@ -368,7 +368,7 @@ class TransformProcessor:
|
||||||
else:
|
else:
|
||||||
return BlockGroup(*content, context=new_context)
|
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)
|
e.content = self.transform(e.content)
|
||||||
|
|
||||||
if "group" in e.classes:
|
if "group" in e.classes:
|
||||||
|
@ -389,6 +389,8 @@ class TransformProcessor:
|
||||||
if "partial" in e.attributes:
|
if "partial" in e.attributes:
|
||||||
# `partial` attribute
|
# `partial` attribute
|
||||||
# Used to include a file which is executed in a different (child) Context.
|
# 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.
|
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"])
|
full_path = os.path.abspath(self.context.dir + "/" + e.attributes["partial"])
|
||||||
pwd = os.path.abspath(".")
|
pwd = os.path.abspath(".")
|
||||||
|
@ -396,13 +398,16 @@ class TransformProcessor:
|
||||||
return nullify(e)
|
return nullify(e)
|
||||||
text = open(self.context.dir + "/" + e.attributes["partial"], "r").read()
|
text = open(self.context.dir + "/" + e.attributes["partial"], "r").read()
|
||||||
path = self.context.dir + "/" + e.attributes["partial"]
|
path = self.context.dir + "/" + e.attributes["partial"]
|
||||||
includedDoc = import_md(text)
|
if e.attributes["type"] == "md":
|
||||||
trusted = True
|
includedDoc = import_md(text)
|
||||||
if "untrusted" in e.attributes and (e.attributes["untrusted"] == True or e.attributes["untrusted"] == 'True'):
|
trusted = True
|
||||||
trusted = False
|
if "untrusted" in e.attributes and (e.attributes["untrusted"] == True or e.attributes["untrusted"] == 'True'):
|
||||||
if not self.context.trusted:
|
trusted = False
|
||||||
trusted = False
|
if not self.context.trusted:
|
||||||
return self.create_Group(*includedDoc.content, new_context=Context(includedDoc, path, self.context, trusted=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:
|
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)
|
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:
|
def transform_Span(self, e: Span) -> Span:
|
||||||
e.content = self.transform(e.content)
|
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:
|
if "group" in e.classes:
|
||||||
# `.group` class for Spans
|
# `.group` class for Spans
|
||||||
# Content of Span is enclosed in a separate context, all attributes are passed as metadata
|
# Content of Span is enclosed in a separate context, all attributes are passed as metadata
|
||||||
|
|
|
@ -4,6 +4,9 @@ subtitle: 'A subtitle'
|
||||||
are_we_there_yet: False
|
are_we_there_yet: False
|
||||||
lang: "en"
|
lang: "en"
|
||||||
---
|
---
|
||||||
|
::: {partial="test-top.html" type="html"}
|
||||||
|
:::
|
||||||
|
|
||||||
[#test-files/test-import.md]{type=md}
|
[#test-files/test-import.md]{type=md}
|
||||||
|
|
||||||
# Hello world!
|
# Hello world!
|
||||||
|
|
Loading…
Reference in a new issue