Update app.py
Browse files
app.py
CHANGED
@@ -505,7 +505,6 @@ def generate_documentation_page():
|
|
505 |
md_file.write(documentation)
|
506 |
st.success(f"Markdown file generated at: {markdown_file_path}")
|
507 |
|
508 |
-
|
509 |
# Helper function to generate PDF
|
510 |
def generate_pdf(documentation):
|
511 |
pdf = FPDF()
|
@@ -519,7 +518,7 @@ def generate_pdf(documentation):
|
|
519 |
pdf.set_font("Courier", style="B", size=12) # Bold for specific lines
|
520 |
pdf.multi_cell(0, 10, line)
|
521 |
elif line.startswith("Project Summary:") or line.startswith("Functionality Summary:") or \
|
522 |
-
|
523 |
pdf.set_font("Courier", style="B", size=14) # Bold larger headers
|
524 |
pdf.multi_cell(0, 10, line)
|
525 |
else:
|
@@ -527,12 +526,14 @@ def generate_pdf(documentation):
|
|
527 |
pdf.multi_cell(0, 10, line)
|
528 |
|
529 |
# Save and download the PDF
|
|
|
|
|
530 |
pdf_file = tempfile.NamedTemporaryFile(delete=False, suffix=".pdf")
|
531 |
pdf.output(pdf_file.name)
|
532 |
st.download_button(
|
533 |
label="Download PDF",
|
534 |
data=open(pdf_file.name, "rb").read(),
|
535 |
-
file_name=
|
536 |
mime="application/pdf",
|
537 |
)
|
538 |
os.unlink(pdf_file.name)
|
@@ -540,16 +541,32 @@ def generate_pdf(documentation):
|
|
540 |
|
541 |
# Helper function to generate Markdown file
|
542 |
def generate_markdown_file(documentation):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
543 |
# Save as a temporary Markdown file
|
544 |
markdown_file = tempfile.NamedTemporaryFile(delete=False, suffix=".md")
|
545 |
with open(markdown_file.name, "w") as f:
|
546 |
-
f.write(
|
547 |
|
548 |
# Download the Markdown file
|
549 |
st.download_button(
|
550 |
label="Download Markdown File",
|
551 |
data=open(markdown_file.name, "rb").read(),
|
552 |
-
file_name=
|
553 |
mime="text/markdown",
|
554 |
)
|
555 |
os.unlink(markdown_file.name)
|
|
|
505 |
md_file.write(documentation)
|
506 |
st.success(f"Markdown file generated at: {markdown_file_path}")
|
507 |
|
|
|
508 |
# Helper function to generate PDF
|
509 |
def generate_pdf(documentation):
|
510 |
pdf = FPDF()
|
|
|
518 |
pdf.set_font("Courier", style="B", size=12) # Bold for specific lines
|
519 |
pdf.multi_cell(0, 10, line)
|
520 |
elif line.startswith("Project Summary:") or line.startswith("Functionality Summary:") or \
|
521 |
+
line.startswith("Functionality Flow:") or line.startswith("Function Documentation:"):
|
522 |
pdf.set_font("Courier", style="B", size=14) # Bold larger headers
|
523 |
pdf.multi_cell(0, 10, line)
|
524 |
else:
|
|
|
526 |
pdf.multi_cell(0, 10, line)
|
527 |
|
528 |
# Save and download the PDF
|
529 |
+
project_name = st.session_state.current_project
|
530 |
+
pdf_file_name = f"{project_name} Documentation.pdf"
|
531 |
pdf_file = tempfile.NamedTemporaryFile(delete=False, suffix=".pdf")
|
532 |
pdf.output(pdf_file.name)
|
533 |
st.download_button(
|
534 |
label="Download PDF",
|
535 |
data=open(pdf_file.name, "rb").read(),
|
536 |
+
file_name=pdf_file_name,
|
537 |
mime="application/pdf",
|
538 |
)
|
539 |
os.unlink(pdf_file.name)
|
|
|
541 |
|
542 |
# Helper function to generate Markdown file
|
543 |
def generate_markdown_file(documentation):
|
544 |
+
project_name = st.session_state.current_project
|
545 |
+
markdown_file_name = f"{project_name} Documentation.md"
|
546 |
+
|
547 |
+
# Format documentation with markdown-specific rules
|
548 |
+
formatted_lines = []
|
549 |
+
for line in documentation.splitlines():
|
550 |
+
if line.startswith("- '") and line.endswith("':"):
|
551 |
+
formatted_lines.append(f"**{line}**") # Bold specific lines
|
552 |
+
elif line.startswith("Project Summary:") or line.startswith("Functionality Summary:") or \
|
553 |
+
line.startswith("Functionality Flow:") or line.startswith("Function Documentation:"):
|
554 |
+
formatted_lines.append(f"# {line}") # Header for large sections
|
555 |
+
else:
|
556 |
+
formatted_lines.append(line)
|
557 |
+
|
558 |
+
formatted_documentation = "\n".join(formatted_lines)
|
559 |
+
|
560 |
# Save as a temporary Markdown file
|
561 |
markdown_file = tempfile.NamedTemporaryFile(delete=False, suffix=".md")
|
562 |
with open(markdown_file.name, "w") as f:
|
563 |
+
f.write(formatted_documentation)
|
564 |
|
565 |
# Download the Markdown file
|
566 |
st.download_button(
|
567 |
label="Download Markdown File",
|
568 |
data=open(markdown_file.name, "rb").read(),
|
569 |
+
file_name=markdown_file_name,
|
570 |
mime="text/markdown",
|
571 |
)
|
572 |
os.unlink(markdown_file.name)
|