replaced markdown parser lib

This commit is contained in:
2026-06-07 03:03:02 -05:00
parent 5e6d576896
commit 83c3ef1594
3 changed files with 111 additions and 35 deletions
+15 -14
View File
@@ -1,12 +1,13 @@
from __future__ import print_function
from __future__ import absolute_import
from builtins import object
import markdown as md
from __future__ import absolute_import, print_function
import codecs
import sys
import os
from .env import css_path, ms_encoding, markdown_type, \
html_dir, html_extension
import sys
from builtins import object
import pycmarkgfm
from .env import css_path, html_dir, html_extension, ms_encoding
class MarkdownConverter(object):
@@ -35,17 +36,17 @@ class MarkdownConverter(object):
"""
def convert(self, src, dst=""):
code = md.markdown(self.read_md(src), extensions=[markdown_type])
code = pycmarkgfm.markdown_to_html(self.read_md(src))
return self.write_html(code, src, dst)
def read_md(self, file_name):
workingdir = os.getcwd()
md_file = codecs.open(
with open(
os.path.join(workingdir, file_name),
encoding=ms_encoding,
mode="r"
)
return md_file.read()
mode="r",
) as md_file:
return md_file.read()
def write_html(self, body, file_name, dst):
html_path = os.path.join(html_dir, file_name + html_extension)
@@ -57,8 +58,8 @@ class MarkdownConverter(object):
except OSError:
pass
html_file = codecs.open(html_path, encoding=ms_encoding, mode="w")
html_file.write(self.html_header + body + self.html_footer)
with open(html_path, encoding=ms_encoding, mode="w") as html_file:
html_file.write(self.html_header + body + self.html_footer)
return html_path