Browse Source

Attach Groups correctly in the tree, Images now support height in HTML.

master
Jan Černohorský 9 months ago
parent
commit
7f3490536e
  1. 2
      src/formatitko/html_generator.py
  2. 20
      src/formatitko/transform_processor.py

2
src/formatitko/html_generator.py

@ -190,6 +190,8 @@ class HTMLGenerator(OutputGenerator):
attributes = self.common_attributes(e) attributes = self.common_attributes(e)
if "width" in e.attributes: if "width" in e.attributes:
attributes["width"] = e.attributes["width"] attributes["width"] = e.attributes["width"]
if "height" in e.attributes:
attributes["height"] = e.attributes["height"]
if e.title: if e.title:
attributes["alt"] = e.title attributes["alt"] = e.title

20
src/formatitko/transform_processor.py

@ -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 e.attributes["no-srcset"] = self.context.get_metadata("no-srcset") if self.context.get_metadata("no-srcset") is not None else False
return e 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 old_context = self.context
self.context = new_context self.context = new_context
content = self.transform([*content])
self.context = old_context
if inline: if inline:
return InlineGroup(*content, context=new_context) g = InlineGroup(*content, context=new_context)
else: 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]: def transform_Para(self, e: Para) -> Union[Para, Div]:
if len(e.content) == 1 and isinstance(e.content[0], Span): 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) new_context = Context(Doc(), self.context.path, self.context, trusted=self.context.trusted)
for attribute, value in e.attributes.items(): for attribute, value in e.attributes.items():
new_context.set_metadata(attribute, value) 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: if "c" in e.attributes:
# Commands can be called multiple ways, this handles the following syntax: # Commands can be called multiple ways, this handles the following syntax:
@ -160,7 +162,7 @@ class TransformProcessor(NOPProcessor):
trusted = False trusted = False
if not self.context.trusted: if not self.context.trusted:
trusted = False 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"]: elif e.attributes["type"] in ["tex", "html"]:
return RawBlock(text, e.attributes["type"]) 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) new_context = Context(Doc(), self.context.path, self.context, trusted=self.context.trusted)
for attribute, value in e.attributes.items(): for attribute, value in e.attributes.items():
new_context.set_metadata(attribute, value) 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: if "c" in e.attributes:
# Commands can be called multiple ways, this handles the following syntax: # 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]: def transform_CodeBlock(self, e: CodeBlock) -> Union[CodeBlock, Div, Null]:
if "markdown" in e.classes and "group" in e.classes: if "markdown" in e.classes and "group" in e.classes:
includedDoc = import_md(e.text) 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 "python" in e.classes and "run" in e.classes:
if not self.context.trusted: if not self.context.trusted:

Loading…
Cancel
Save