import os from flask import Blueprint, jsonify, current_app, send_from_directory from ..services.markdown_service import ( convert_markdown_to_html, wrap_with_styles, save_html, copy_images, load_markdown_file ) from markdown_it import MarkdownIt from mdit_py_plugins import texmath bp = Blueprint("markdown", __name__) @bp.route("/---markdown", methods=["GET"]) def convert_md(course_id, chapter_name, lesson_name): print(f"convert_md: {course_id}, {chapter_name}, {lesson_name}") md_file = load_markdown_file(course_id, chapter_name, lesson_name) # 直接返回Markdown源文件内容,不进行服务器端渲染 return jsonify({"markdown_content": md_file}) # 提供静态文件访问 @bp.route("/static/") def serve_static(filename): return send_from_directory(current_app.config["STATIC_DIR"], filename) def wrap_with_styles(html_content): # 在HTML中添加MathJax支持 mathjax_script = """ """ # 包装HTML内容和样式 return f""" Document {mathjax_script} {html_content} """