""" Markdown render. use https://github.com/lepture/mistune render to html, then print with my style. """ import logging import mistune import re from prompt_toolkit.formatted_text import to_formatted_text, HTML logger = logging.getLogger(__name__) class TerminalRender(mistune.HTMLRenderer): def _to_title(self, text): return f"{text}\n{'='*len(text)}\n" def paragraph(self, text): return text + "\n\n" def block_code(self, code, info=None): code = "\n".join([" " + line for line in code.splitlines()]) return super().block_code(code) def heading(self, text, level): if level == 2: header_text = self._to_title(text) return super().heading(header_text, 2) return super().heading(self._to_title(text), level) def list(self, body, ordered, *args, **kwargs): """Rendering list tags like ``