From aa6f4c4bc861f0e054d066683c84611af1402405 Mon Sep 17 00:00:00 2001 From: Sami Mokaddem Date: Fri, 8 Nov 2024 09:53:49 +0100 Subject: [PATCH] chg: [expansion:convert_markdown_to_pdf] Added support of `margin` configuration --- .../modules/expansion/convert_markdown_to_pdf.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/misp_modules/modules/expansion/convert_markdown_to_pdf.py b/misp_modules/modules/expansion/convert_markdown_to_pdf.py index 8eac5b68..f715d2de 100755 --- a/misp_modules/modules/expansion/convert_markdown_to_pdf.py +++ b/misp_modules/modules/expansion/convert_markdown_to_pdf.py @@ -7,7 +7,7 @@ import pandoc misperrors = {'error': 'Error'} mispattributes = {'input': ['text'], 'output': ['text']} moduleinfo = { - 'version': '0.1', + 'version': '0.2', 'author': 'Sami Mokaddem', 'description': 'Render the markdown (under GFM) into PDF. Requires pandoc (https://pandoc.org/) and wkhtmltopdf (https://wkhtmltopdf.org/).', 'module-type': ['expansion'], @@ -20,10 +20,13 @@ moduleinfo = { 'output': '', } +moduleconfig = [ + 'margin', +] -def convert(markdown): + +def convert(markdown, margin='3'): doc = pandoc.read(markdown, format='gfm') - margin = '3' options = [ '--pdf-engine=wkhtmltopdf', f'-V margin-left={margin}', @@ -45,7 +48,11 @@ def handler(q=False): data = json.loads(data) markdown = data.get('markdown') try: - rendered = convert(markdown) + margin = '3' + if 'config' in request['config']: + if request['config'].get('margin'): + margin = request['config'].get('margin') + rendered = convert(markdown, margin=margin) except Exception as e: rendered = f'Error: {e}' @@ -59,4 +66,5 @@ def introspection(): def version(): + moduleinfo['config'] = moduleconfig return moduleinfo