diff options
Diffstat (limited to 'responsive/md2html')
| -rwxr-xr-x | responsive/md2html | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/responsive/md2html b/responsive/md2html new file mode 100755 index 0000000..571c8d7 --- /dev/null +++ b/responsive/md2html | |||
| @@ -0,0 +1,37 @@ | |||
| 1 | #!/usr/bin/env python3 | ||
| 2 | import io | ||
| 3 | import sys | ||
| 4 | |||
| 5 | import markdown | ||
| 6 | from markdown.extensions.toc import TocExtension | ||
| 7 | |||
| 8 | sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding="utf-8") | ||
| 9 | sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8") | ||
| 10 | |||
| 11 | sys.stdout.write("<div class='markdown-body'>") | ||
| 12 | sys.stdout.flush() | ||
| 13 | |||
| 14 | try: | ||
| 15 | markdown.markdownFromFile( | ||
| 16 | output_format="html5", | ||
| 17 | extensions=[ | ||
| 18 | "markdown.extensions.fenced_code", | ||
| 19 | "markdown.extensions.codehilite", | ||
| 20 | "markdown.extensions.tables", | ||
| 21 | "markdown.extensions.sane_lists", | ||
| 22 | "markdown.extensions.admonition", | ||
| 23 | TocExtension(anchorlink=True, permalink=True), | ||
| 24 | ], | ||
| 25 | extension_configs={ | ||
| 26 | "markdown.extensions.codehilite": { | ||
| 27 | "css_class": "highlight", | ||
| 28 | "guess_lang": False, | ||
| 29 | } | ||
| 30 | }, | ||
| 31 | ) | ||
| 32 | except Exception as e: | ||
| 33 | sys.stdout.write(f"<p>Error rendering markdown: {e}</p>") | ||
| 34 | sys.stdin.seek(0) | ||
| 35 | sys.stdout.write(f"<pre>{sys.stdin.read()}</pre>") | ||
| 36 | |||
| 37 | sys.stdout.write("</div>") | ||
