|
|
@ -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: |
|
|
|