Lets test

This commit is contained in:
2024-12-12 19:55:30 +01:00
parent e4887345a5
commit c6ac4599f4
15 changed files with 173 additions and 2991 deletions

View File

@@ -20,6 +20,7 @@ def box(title, content):
</div>
'''
def note(content):
"""Render a note component."""
return f'''
@@ -37,7 +38,7 @@ def warning(content):
'''
def create_jinja_environment():
"""Set up Jinja2 environment and register custom components."""
"""Create and configure the Jinja2 environment."""
env = Environment(loader=DictLoader({"base_template": "{{ content | safe }}"}))
env.globals.update({
"img_left_overlay": img_left_overlay,
@@ -59,12 +60,15 @@ def render_markdown_with_jinja(markdown_content: str):
"""
# Step 1: Convert Markdown to HTML and extract metadata
md = markdown.Markdown(extensions=["extra", "nl2br", "meta"])
html_content = md.convert(markdown_content)
intermediate_html = md.convert(markdown_content)
metadata = {key: " ".join(value) for key, value in md.Meta.items()} if md.Meta else {}
# Step 2: Render the HTML with Jinja2 to apply custom tags
# Step 2: Pass the resulting HTML with Jinja2 custom tags through Jinja2
env = create_jinja_environment()
template = env.get_template("base_template")
final_html = template.render(content=html_content)
final_html = template.render(content=intermediate_html)
return final_html, metadata
# Step 3: Re-render final_html in Jinja2 for embedded tags like {{ box(...) }}
final_output = env.from_string(final_html).render()
return final_output, metadata