File size: 1,067 Bytes
83491c8
 
 
 
 
 
 
59612fb
de7fe63
59612fb
86893ca
83491c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5d37369
 
83491c8
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# app.py
from flask import Flask, render_template, request, send_file
import markdown
import os
from utils.markdown_to_docx import save_as_docx
from utils.markdown_to_pdf import save_as_pdf

# Set environment variables to ensure playwright finds Chromium
os.environ["PLAYWRIGHT_BROWSERS_PATH"] = "/usr/local/share/pw-browsers"
os.environ["PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD"] = "1"

app = Flask(__name__)

@app.route("/")
def index():
    return render_template("index.html")

@app.route("/export", methods=["POST"])
def export():
    md_text = request.form["markdown"]
    export_type = request.form["type"]  # 'docx' or 'pdf'

    if export_type == "docx":
        output_path = save_as_docx(md_text)
    elif export_type == "pdf":
        output_path = save_as_pdf(md_text)
    else:
        return "Unsupported format", 400

    return send_file(output_path, as_attachment=True)

if __name__ == "__main__":
    output_dir = "/tmp/output"
    os.makedirs(output_dir, exist_ok=True)
    port = int(os.environ.get("PORT", 7860))
    app.run(host="0.0.0.0", port=port)