Update app.py
Browse files
app.py
CHANGED
@@ -473,18 +473,21 @@ def generate_pdf(documentation):
|
|
473 |
pdf = FPDF()
|
474 |
pdf.set_auto_page_break(auto=True, margin=15)
|
475 |
pdf.add_page()
|
476 |
-
pdf.set_font("
|
477 |
|
478 |
-
#
|
479 |
for line in documentation.splitlines():
|
|
|
|
|
|
|
|
|
480 |
if line.startswith("Project Summary:") or line.startswith("Functionality Summary:") or \
|
481 |
line.startswith("Functionality Flow:") or line.startswith("Function Documentation:"):
|
482 |
-
pdf.set_font("
|
483 |
-
|
484 |
-
pdf.set_font("
|
485 |
else:
|
486 |
-
pdf.
|
487 |
-
pdf.multi_cell(0, 10, line)
|
488 |
|
489 |
# Save and download the PDF
|
490 |
pdf_file = tempfile.NamedTemporaryFile(delete=False, suffix=".pdf")
|
@@ -499,15 +502,33 @@ def generate_pdf(documentation):
|
|
499 |
|
500 |
# Helper function to generate Markdown file
|
501 |
def generate_markdown_file(documentation):
|
502 |
-
|
503 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
504 |
|
505 |
-
# Save
|
506 |
markdown_file = tempfile.NamedTemporaryFile(delete=False, suffix=".md")
|
507 |
with open(markdown_file.name, "w") as f:
|
508 |
f.write(formatted_documentation)
|
509 |
|
510 |
-
#
|
511 |
st.download_button(
|
512 |
label="Download Markdown File",
|
513 |
data=open(markdown_file.name, "rb").read(),
|
|
|
473 |
pdf = FPDF()
|
474 |
pdf.set_auto_page_break(auto=True, margin=15)
|
475 |
pdf.add_page()
|
476 |
+
pdf.set_font("Courier", size=12) # Monospaced font for IDE-like appearance
|
477 |
|
478 |
+
# Process and format content
|
479 |
for line in documentation.splitlines():
|
480 |
+
# Remove asterisks and backticks
|
481 |
+
line = line.replace("*", "").replace("`", "'")
|
482 |
+
|
483 |
+
# Detect headers and adjust formatting
|
484 |
if line.startswith("Project Summary:") or line.startswith("Functionality Summary:") or \
|
485 |
line.startswith("Functionality Flow:") or line.startswith("Function Documentation:"):
|
486 |
+
pdf.set_font("Courier", style="B", size=14)
|
487 |
+
pdf.cell(0, 10, line, ln=True)
|
488 |
+
pdf.set_font("Courier", size=12) # Reset font for content
|
489 |
else:
|
490 |
+
pdf.multi_cell(0, 10, line.strip()) # Handle regular content
|
|
|
491 |
|
492 |
# Save and download the PDF
|
493 |
pdf_file = tempfile.NamedTemporaryFile(delete=False, suffix=".pdf")
|
|
|
502 |
|
503 |
# Helper function to generate Markdown file
|
504 |
def generate_markdown_file(documentation):
|
505 |
+
"""
|
506 |
+
Generate a Markdown file from the documentation with IDE-like formatting.
|
507 |
+
Adjustments:
|
508 |
+
- Removes asterisks (*)
|
509 |
+
- Replaces backticks (`) with single quotes (')
|
510 |
+
- Removes extra spaces between section headers and their content
|
511 |
+
- Removes Markdown-specific delimiters (e.g., ``` at the top and bottom)
|
512 |
+
"""
|
513 |
+
# Process and format content
|
514 |
+
formatted_documentation = ""
|
515 |
+
for line in documentation.splitlines():
|
516 |
+
# Remove asterisks and backticks
|
517 |
+
line = line.replace("*", "").replace("`", "'")
|
518 |
+
|
519 |
+
# Add a newline only for headers for better structure in Markdown
|
520 |
+
if line.startswith("Project Summary:") or line.startswith("Functionality Summary:") or \
|
521 |
+
line.startswith("Functionality Flow:") or line.startswith("Function Documentation:"):
|
522 |
+
formatted_documentation += f"## {line.strip()}\n"
|
523 |
+
else:
|
524 |
+
formatted_documentation += f"{line.strip()}\n"
|
525 |
|
526 |
+
# Save to a temporary Markdown file
|
527 |
markdown_file = tempfile.NamedTemporaryFile(delete=False, suffix=".md")
|
528 |
with open(markdown_file.name, "w") as f:
|
529 |
f.write(formatted_documentation)
|
530 |
|
531 |
+
# Allow the user to download the Markdown file
|
532 |
st.download_button(
|
533 |
label="Download Markdown File",
|
534 |
data=open(markdown_file.name, "rb").read(),
|