Skip to content

Commit

Permalink
chg: [expansion:convert_markdown_to_pdf] Added support of margin co…
Browse files Browse the repository at this point in the history
…nfiguration
  • Loading branch information
mokaddem committed Nov 8, 2024
1 parent 6a3557b commit aa6f4c4
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions misp_modules/modules/expansion/convert_markdown_to_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
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'],
Expand All @@ -20,10 +20,13 @@
'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}',
Expand All @@ -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}'

Expand All @@ -59,4 +66,5 @@ def introspection():


def version():
moduleinfo['config'] = moduleconfig
return moduleinfo

0 comments on commit aa6f4c4

Please sign in to comment.