Separate context init for transform processor into separate function, add option to not make images clickable.
This commit is contained in:
parent
f14f28d3a4
commit
f0d939a65b
2 changed files with 17 additions and 7 deletions
|
@ -208,6 +208,10 @@ class HTMLGenerator(OutputGenerator):
|
|||
else:
|
||||
attributes["src"] = url
|
||||
|
||||
if e.attributes["no-img-link"]:
|
||||
self.write(self.single_tag("img", attributes))
|
||||
return
|
||||
|
||||
img = RawInline(self.single_tag("img", attributes))
|
||||
link = Link(img, url=url)
|
||||
|
||||
|
|
|
@ -40,6 +40,15 @@ class TransformProcessor(NOPProcessor):
|
|||
def add_command_module(self, module: Union[dict[str, CommandCallable], ModuleType], module_name: str=""):
|
||||
self._command_modules.append((module, module_name))
|
||||
|
||||
def init_context(self, e: Doc) -> Context:
|
||||
if self.context is not None:
|
||||
raise DoubleDocError()
|
||||
self.context = Context(e, self.root_file_path)
|
||||
for module, module_name in self._command_modules:
|
||||
self.context.add_commands_from_module(module, module_name)
|
||||
e.content = [BlockGroup(*e.content, context=self.context)]
|
||||
return self.context
|
||||
|
||||
def get_pretransformers(self) -> list[Callable[[ELCl],ELCl]]:
|
||||
return super().get_pretransformers()+[self.handle_if_attribute, self.handle_ifnot_attribute]
|
||||
|
||||
|
@ -71,12 +80,7 @@ class TransformProcessor(NOPProcessor):
|
|||
raise err
|
||||
|
||||
def transform_Doc(self, e: Doc) -> Doc:
|
||||
if self.context is not None:
|
||||
raise DoubleDocError()
|
||||
self.context = Context(e, self.root_file_path)
|
||||
for module, module_name in self._command_modules:
|
||||
self.context.add_commands_from_module(module, module_name)
|
||||
e.content = [BlockGroup(*e.content, context=self.context)]
|
||||
self.init_context(e)
|
||||
e.content = self.transform(e.content)
|
||||
return e
|
||||
|
||||
|
@ -95,8 +99,10 @@ class TransformProcessor(NOPProcessor):
|
|||
e.content = self.transform(e.content)
|
||||
# OG now has Context so this is not needed per se, but I'm keeping this here for the handling of attribute > context > default value
|
||||
# Pass down "no-srcset" metadatum as attribute down to images.
|
||||
if not "no-srcset" in e.attributes:
|
||||
if "no-srcset" not in e.attributes:
|
||||
e.attributes["no-srcset"] = self.context.get_metadata("no-srcset") if self.context.get_metadata("no-srcset") is not None else False
|
||||
if "no-img-link" not in e.attributes:
|
||||
e.attributes["no-img-link"] = self.context.get_metadata("no-img-link") if self.context.get_metadata("no-img-link") is not None else False
|
||||
return e
|
||||
|
||||
def create_Group(self, *content, new_context: Context, replaced:Element, inline: bool=False) -> Group:
|
||||
|
|
Loading…
Reference in a new issue