processint to html

This commit is contained in:
2026-01-23 13:53:29 -07:00
parent c18b6f1450
commit 4f34c94a40
2 changed files with 47 additions and 1 deletions
+45
View File
@@ -1,5 +1,50 @@
from pathlib import Path
from mdtohtml import mdtohtml
md = """
#This is a header
THis is a paragrah with **bold** text
This is *italic* text
and and unordered list
- one item
- two item
- three item
"""
srcdir = Path("markdown")
destdir = Path("publish")
def main():
print("Hello from resume!")
html = mdtohtml(md)
print(html)
# html
# process all files ending with '.md' in srcdir to html
# get the files
if not srcdir.is_dir():
return f'Error: "{srcdir}" is not a directory or does not exist'
filelist = list(srcdir.glob('*.md'))
# mk destdir if not exist
if not destdir.is_dir():
destdir.mkdir()
# process through mdtohtml
for infile in filelist:
outfile = destdir / infile.name
outfile = outfile.with_suffix(".html")
print(f" processing '{infile}' to '{outfile}")
with infile.open(mode='r', encoding='utf-8') as f:
mdsrc = f.read()
html = mdtohtml(mdsrc)
with outfile.open(mode='w', encoding='utf-8') as f:
f.write(html)
if __name__ == "__main__":
+2 -1
View File
@@ -1,6 +1,7 @@
from markdown_it import MarkdownIt
md = MarkdownIt()
md = MarkdownIt("commonmark").enable('table')
def mdtohtml(mdsrc):
return md.render(mdsrc)