不再使用markdown编译html,而是直接markdown源文件,前端进行渲染
This commit is contained in:
@@ -14,17 +14,8 @@ bp = Blueprint("markdown", __name__)
|
||||
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解析器,启用数学公式支持
|
||||
md = MarkdownIt()
|
||||
md.use(texmath.texmath_plugin) # 添加数学公式插件
|
||||
# 转换markdown为html(包含公式标记)
|
||||
html = md.render(md_file)
|
||||
# 包装样式时添加MathJax支持,用于在浏览器中渲染公式
|
||||
html_with_styles = wrap_with_styles(html)
|
||||
# 保存HTML文件到static
|
||||
html_output_path = os.path.join(current_app.config["STATIC_DIR"], f"{course_id}-{chapter_name}-{lesson_name}.html")
|
||||
save_html(html_with_styles, html_output_path)
|
||||
return jsonify({"html_url": f"/static/{course_id}-{chapter_name}-{lesson_name}.html"})
|
||||
# 直接返回Markdown源文件内容,不进行服务器端渲染
|
||||
return jsonify({"markdown_content": md_file})
|
||||
|
||||
# 提供静态文件访问
|
||||
@bp.route("/static/<path:filename>")
|
||||
|
||||
Reference in New Issue
Block a user