From 3d85dbaa4788db7318a4583eaad9f12e012beda1 Mon Sep 17 00:00:00 2001 From: treatmesubj Date: Tue, 14 Mar 2023 17:18:44 -0500 Subject: [PATCH] utf-8 --- build/lib/httpmdhtml/md_to_html.py | 7 ++++--- httpmdhtml/md_to_html.py | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/build/lib/httpmdhtml/md_to_html.py b/build/lib/httpmdhtml/md_to_html.py index 2403d00..0e24e0b 100644 --- a/build/lib/httpmdhtml/md_to_html.py +++ b/build/lib/httpmdhtml/md_to_html.py @@ -8,7 +8,6 @@ import argparse import re from markdown_it import MarkdownIt -# from markdown_it.presets import gfm_like from bs4 import BeautifulSoup, element @@ -28,7 +27,9 @@ def markdown_to_html(MarkdownIt_obj, in_file_path, out_file_path="tmp.html", css="""body { background-color: #272822; color: white; font-family: Courier; } a[href] { color: #66d9ef; } code { color: #ae81ff; background-color: #272b33; border-radius: 6px; } - table, th, td { border: 1px solid; border-collapse: collapse; padding-left: 4px; padding-right: 4px; }""" + table, th, td { border: 1px solid; border-collapse: collapse; padding-left: 4px; padding-right: 4px; } + h1, h2, h3, h4, h5 { margin-top: 0px; margin-bottom: 0px; } + p { margin-top: 0px; }""" soup.select_one("style").string = css if encode_local_images: img_elems = soup.select("img") @@ -43,7 +44,7 @@ def markdown_to_html(MarkdownIt_obj, in_file_path, out_file_path="tmp.html", if __name__ == "__main__": - # gfm_like.make(); MarkdownIt_obj = MarkdownIt("gfm-like") + MarkdownIt_obj = MarkdownIt("commonmark").enable("table").enable("strikethrough") parser = argparse.ArgumentParser() parser.add_argument('--in_file_path', '-i', required=True, diff --git a/httpmdhtml/md_to_html.py b/httpmdhtml/md_to_html.py index 0e24e0b..770d140 100644 --- a/httpmdhtml/md_to_html.py +++ b/httpmdhtml/md_to_html.py @@ -19,6 +19,8 @@ def markdown_to_html(MarkdownIt_obj, in_file_path, out_file_path="tmp.html", html_text = MarkdownIt_obj.render(text) # pretty CSS soup = BeautifulSoup(html_text, 'html5lib') # adds , , + soup.select_one('head').append(soup.new_tag("meta")) + soup.select_one('meta').attrs['charset'] = "UTF-8" soup.select_one('head').append(soup.new_tag("style")) if css_file: with open(css_file, 'r') as f: