diff --git a/app.py b/app.py index aa78e0e..9d5a0dc 100644 --- a/app.py +++ b/app.py @@ -1,30 +1,15 @@ from fastapi import FastAPI, Request from fastapi.staticfiles import StaticFiles +from fastapi.responses import HTMLResponse from fastapi.templating import Jinja2Templates import json import os -from fastapi import FastAPI -from fastapi.responses import HTMLResponse -from contextlib import asynccontextmanager -from markdown_render import render_markdown_with_jinja + + + from starlette.middleware.httpsredirect import HTTPSRedirectMiddleware - - - - -# Context manager for app lifespan -@asynccontextmanager -async def lifespan(app: FastAPI): - print("App startup: Processing Markdown files...") - process_markdown_files("./data", "./data") # Process all Markdown files - print("Markdown processing complete!") - yield # Allow the app to start - print("App shutdown: Cleanup complete.") - -app = FastAPI(lifespan=lifespan) -app.mount("/data", StaticFiles(directory="data"), name="data") - +app = FastAPI() # Mount static files app.mount("/static", StaticFiles(directory="static"), name="static") @@ -38,22 +23,34 @@ with open("mock_data.json") as file: data = json.load(file) @app.get("/test", response_class=HTMLResponse) -async def home_test(): - # Load the Markdown content from a file - with open("templates/example.md", "r") as f: - markdown_content = f.read() +async def mark_test(): + markdown_content = """ + # Custom Tags Test - # Render Markdown first, then inject Jinja2 components - rendered_html = render_markdown_with_jinja(markdown_content) + Here is an image overlay: + {img-left-overlay: src=my-cat.png} - # Wrap in a base HTML layout - html_template = f""" + Here is a box: + {box: title=Important, content=This is a reusable box.} + + And a note: + {note: content=This is a note for the user.} + + Warning section: + {warning: content=Pay attention to this warning!} + """ + + # Render Markdown content + rendered_html = md_renderer.render( markdown_content ) + + # Wrap in a basic template + template = f"""
-