diff --git a/legalmd/__main__.py b/legalmd/__main__.py index 11c3f11..b987840 100644 --- a/legalmd/__main__.py +++ b/legalmd/__main__.py @@ -40,6 +40,9 @@ with renderer_cls() as renderer: doc.author = rawdoc.get('author', '') doc.footer = rawdoc.get('footer', '') + doc.lmarg = rawdoc.get('lmarg', '1cm') + doc.contentsmarg = rawdoc.get('contentsmarg', '1cm') + doc.full_label_map = {} # Preprocess custom tokens diff --git a/legalmd/latex_renderer.py b/legalmd/latex_renderer.py index bda86df..5e6e961 100644 --- a/legalmd/latex_renderer.py +++ b/legalmd/latex_renderer.py @@ -1,5 +1,5 @@ # legalmd: Markdown-based legal markup -# Copyright © 2019 Lee Yingtong Li (RunasSudo) +# Copyright © 2019, 2021 Lee Yingtong Li (RunasSudo) # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by @@ -19,7 +19,7 @@ import hashlib import mistletoe import mistletoe.latex_renderer -LMARG = '1cm' +doc = None def format(fstr, *args, **kwargs): fstr2 = fstr @@ -29,7 +29,8 @@ def format(fstr, *args, **kwargs): fstr2 = fstr2.replace('<', '{') fstr2 = fstr2.replace('>', '}') - kwargs['lmarg'] = LMARG + kwargs['lmarg'] = doc.lmarg + kwargs['contentsmarg'] = doc.contentsmarg return fstr2.format(*args, **kwargs) @@ -52,6 +53,7 @@ class LaTeXRenderer(mistletoe.latex_renderer.LaTeXRenderer): def render_raw_text(self, token): result = super().render_raw_text(token) + result = result.replace('%', r'\%') result = result.replace('★★★', r'\texorpdfstring{\freeserif ★★★}{★★★}') return result @@ -135,10 +137,11 @@ class LaTeXRenderer(mistletoe.latex_renderer.LaTeXRenderer): if token.level == 3: # Section heading_last, self.heading_last = self.heading_last, False - return format(r'{\par\leftskip=\quotemargin\bfseries\makebox[][l]{