|
|
@ -99,15 +99,17 @@ class TransformProcessor(NOPProcessor): |
|
|
|
e.attributes["no-srcset"] = self.context.get_metadata("no-srcset") if self.context.get_metadata("no-srcset") is not None else False |
|
|
|
return e |
|
|
|
|
|
|
|
def create_Group(self, *content, new_context: Context, inline: bool=False) -> Group: |
|
|
|
def create_Group(self, *content, new_context: Context, replaced:Element, inline: bool=False) -> Group: |
|
|
|
old_context = self.context |
|
|
|
self.context = new_context |
|
|
|
content = self.transform([*content]) |
|
|
|
self.context = old_context |
|
|
|
if inline: |
|
|
|
return InlineGroup(*content, context=new_context) |
|
|
|
g = InlineGroup(*content, context=new_context) |
|
|
|
else: |
|
|
|
return BlockGroup(*content, context=new_context) |
|
|
|
g = BlockGroup(*content, context=new_context) |
|
|
|
attach(g, replaced.parent, replaced.location, replaced.index) |
|
|
|
g = self.transform(g) |
|
|
|
self.context = old_context |
|
|
|
return g |
|
|
|
|
|
|
|
def transform_Para(self, e: Para) -> Union[Para, Div]: |
|
|
|
if len(e.content) == 1 and isinstance(e.content[0], Span): |
|
|
@ -131,7 +133,7 @@ class TransformProcessor(NOPProcessor): |
|
|
|
new_context = Context(Doc(), self.context.path, self.context, trusted=self.context.trusted) |
|
|
|
for attribute, value in e.attributes.items(): |
|
|
|
new_context.set_metadata(attribute, value) |
|
|
|
return self.create_Group(*e.content, new_context=new_context) |
|
|
|
return self.create_Group(*e.content, replaced=e, new_context=new_context) |
|
|
|
|
|
|
|
if "c" in e.attributes: |
|
|
|
# Commands can be called multiple ways, this handles the following syntax: |
|
|
@ -160,7 +162,7 @@ class TransformProcessor(NOPProcessor): |
|
|
|
trusted = False |
|
|
|
if not self.context.trusted: |
|
|
|
trusted = False |
|
|
|
return self.create_Group(*includedDoc.content, new_context=Context(includedDoc, path, self.context, trusted=trusted)) |
|
|
|
return self.create_Group(*includedDoc.content, replaced=e, new_context=Context(includedDoc, path, self.context, trusted=trusted)) |
|
|
|
elif e.attributes["type"] in ["tex", "html"]: |
|
|
|
return RawBlock(text, e.attributes["type"]) |
|
|
|
|
|
|
@ -192,7 +194,7 @@ class TransformProcessor(NOPProcessor): |
|
|
|
new_context = Context(Doc(), self.context.path, self.context, trusted=self.context.trusted) |
|
|
|
for attribute, value in e.attributes.items(): |
|
|
|
new_context.set_metadata(attribute, value) |
|
|
|
return self.create_Group(*e.content, new_context=new_context, inline=True) |
|
|
|
return self.create_Group(*e.content, replaced=e, new_context=new_context, inline=True) |
|
|
|
|
|
|
|
if "c" in e.attributes: |
|
|
|
# Commands can be called multiple ways, this handles the following syntax: |
|
|
@ -253,7 +255,7 @@ class TransformProcessor(NOPProcessor): |
|
|
|
def transform_CodeBlock(self, e: CodeBlock) -> Union[CodeBlock, Div, Null]: |
|
|
|
if "markdown" in e.classes and "group" in e.classes: |
|
|
|
includedDoc = import_md(e.text) |
|
|
|
return self.create_Group(*includedDoc.content, new_context=Context(includedDoc, self.context.path, self.context, self.context.trusted)) |
|
|
|
return self.create_Group(*includedDoc.content, replaced=e, new_context=Context(includedDoc, self.context.path, self.context, self.context.trusted)) |
|
|
|
|
|
|
|
if "python" in e.classes and "run" in e.classes: |
|
|
|
if not self.context.trusted: |
|
|
|