# legalmd: Markdown-based legal markup # Copyright © 2019 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 # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . import argparse import re import sys import frontmatter import mistletoe from . import legal_token from . import latex_renderer, rtf_renderer parser = argparse.ArgumentParser() parser.add_argument('--format', default='tex', choices=['tex', 'rtf']) parser.add_argument('filename') args = parser.parse_args() rawdoc = frontmatter.load(args.filename) renderer_cls = {'tex': latex_renderer.LaTeXRenderer, 'rtf': rtf_renderer.RTFRenderer}[args.format] with renderer_cls() as renderer: doc = mistletoe.Document(rawdoc.content.splitlines()) doc.title = rawdoc.get('title', '') doc.author = rawdoc.get('author', '') doc.footer = rawdoc.get('footer', '') print(renderer.render(doc))