diff options
author | Navan Chauhan <navanchauhan@gmail.com> | 2024-04-03 09:36:58 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-03 09:36:58 -0600 |
commit | 84ad5d8360fb0683f12f9bae8f29d6b36964dde3 (patch) | |
tree | 64bb1d9675ac3d6a3604d512311a754b08c53be2 /generate_me.py | |
parent | 0e4b5fcc164cd8432678bdffd58b8c123acee186 (diff) | |
parent | d00b2da99ef2d498074a6e4eb8d80995cdfc4476 (diff) |
Merge branch 'vanilla-ssg' into dependabot/pip/jinja2-3.1.3
Diffstat (limited to 'generate_me.py')
-rw-r--r-- | generate_me.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/generate_me.py b/generate_me.py index fa39bf9..736cece 100644 --- a/generate_me.py +++ b/generate_me.py @@ -1,4 +1,4 @@ -from markdown2 import Markdown +from markdown3 import Markdown import os from jinja2 import Environment, FileSystemLoader from distutils.dir_util import copy_tree @@ -7,6 +7,8 @@ import email.utils from helper_libs.image_utils import ImageText from PIL import Image +import re + templates = Environment(loader=FileSystemLoader("templates")) src_folder = "Content" out_folder = "docs" @@ -28,9 +30,13 @@ md = Markdown( "task_list", "tables", "target-blank-links", + "header-ids", + "latex", ] ) +# h1 tag regex ignoring any attributes +h1_tag = re.compile(r"<h1[^>]*>(.*?)</h1>") def render_markdown_post( html, metadata=None, template="post.html", posts=[], title=None @@ -83,7 +89,7 @@ for x in os.walk(src_folder): fpath = os.path.join(x[0], y) with open(fpath) as f: _html = md.convert(f.read()) - _post_title = _html[4 : _html.find("</h1>")] + _post_title = re.search(h1_tag, _html).group(1) _post = _html.metadata _post["title"] = _post_title _post["link"] = fpath.replace(src_folder, "").replace( |