From 897b4de4f58b9f9e3830e7a658c838e7eb29ac97 Mon Sep 17 00:00:00 2001 From: vicky Date: Tue, 17 May 2022 20:16:58 +0200 Subject: [PATCH] added format_optionals and image --- src/bootstraparse/modules/export.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/bootstraparse/modules/export.py b/src/bootstraparse/modules/export.py index 140dc25..3709a97 100644 --- a/src/bootstraparse/modules/export.py +++ b/src/bootstraparse/modules/export.py @@ -17,6 +17,22 @@ final output. ExportResponse = namedtuple("ExportResponse", ["start", "end"]) +def format_optionals(optionals): + """ + Function handling parser output optional object, splitting it between html_insert and class_insert + on one hand and var on the other hand. + rtype: str + """ + if optionals != '': + h, c = optionals.content.html_insert, optionals.content.class_insert + else: + return '' + if h != '': + h = h.content.html_insert + output = f'''{' '.join(h)}{' ' if h and c else ''}{f'class="{c}"' if c else ''}''' + return output + + class ExportManager: """ Transforms ExportRequest tuples to ExportResponse tuples with the config-provided appropriate markup. @@ -33,6 +49,7 @@ class ExportManager: "t_head": self.t_transform, "t_row": self.t_transform, "t_cell": self.t_transform, + "image": self.image_transform, } def __call__(self, export_request): @@ -132,6 +149,14 @@ class ExportManager: start = start.format(col_span=export_request.others["col_span"]) return ExportResponse(start, end) + def image_transform(self, export_request): + """ + Specific template for images. + """ + start, end, optionals = self._get_template(export_request) + end = end.format(optionals=optionals) + return ExportResponse(start, end) + if __name__ == '__main__': # pragma: no cover herbert = ExportManager(cnoifg=None, templates=None)