Spaces:
Running
Running
update pages
Browse files- document_generator_v3.py +18 -26
document_generator_v3.py
CHANGED
|
@@ -402,24 +402,6 @@ class MarkdownConverter:
|
|
| 402 |
def slugify(text: str) -> str:
|
| 403 |
return re.sub(r'\W+', '-', text.lower())
|
| 404 |
|
| 405 |
-
@classmethod
|
| 406 |
-
def generate_toc(cls, sections: List[Dict]) -> str:
|
| 407 |
-
toc = "<div style='page-break-before: always;'></div>\n\n"
|
| 408 |
-
toc += "<h2 style='color: #2c3e50; text-align: center;'>Table of Contents</h2>\n\n"
|
| 409 |
-
toc += "<nav style='background-color: #f8f9fa; padding: 20px; border-radius: 5px; line-height: 1.6;'>\n\n"
|
| 410 |
-
for section in sections:
|
| 411 |
-
section_number = section['PageNumber']
|
| 412 |
-
section_title = section['Title']
|
| 413 |
-
toc += f"<p><a href='#{cls.slugify(section_title)}' style='color: #3498db; text-decoration: none;'>{section_number}. {section_title}</a></p>\n\n"
|
| 414 |
-
|
| 415 |
-
for subsection in section.get('Subsections', []):
|
| 416 |
-
subsection_number = subsection['PageNumber']
|
| 417 |
-
subsection_title = subsection['Title']
|
| 418 |
-
toc += f"<p style='margin-left: 20px;'><a href='#{cls.slugify(subsection_title)}' style='color: #2980b9; text-decoration: none;'>{subsection_number} {subsection_title}</a></p>\n\n"
|
| 419 |
-
|
| 420 |
-
toc += "</nav>\n\n"
|
| 421 |
-
return toc
|
| 422 |
-
|
| 423 |
@classmethod
|
| 424 |
def convert_to_markdown(cls, document: Dict) -> str:
|
| 425 |
markdown = "<div style='text-align: center; padding-top: 33vh;'>\n\n"
|
|
@@ -428,23 +410,33 @@ class MarkdownConverter:
|
|
| 428 |
markdown += f"<p style='color: #95a5a6;'>Version {document['Version']} | {document['Date']}</p>\n\n"
|
| 429 |
markdown += "</div>\n\n"
|
| 430 |
|
| 431 |
-
|
|
|
|
|
|
|
|
|
|
| 432 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 433 |
markdown += "<div style='max-width: 800px; margin: 0 auto; font-family: \"Segoe UI\", Arial, sans-serif; line-height: 1.6;'>\n\n"
|
| 434 |
|
| 435 |
-
for section in document['
|
| 436 |
markdown += "<div style='page-break-before: always;'></div>\n\n"
|
| 437 |
section_number = section['PageNumber']
|
| 438 |
section_title = section['Title']
|
| 439 |
markdown += f"<h2 id='{cls.slugify(section_title)}' style='color: #2c3e50; border-bottom: 1px solid #bdc3c7; padding-bottom: 5px;'>{section_number}. {section_title}</h2>\n\n"
|
| 440 |
markdown += f"<div style='color: #34495e; margin-bottom: 20px;'>\n\n{section['Content']}\n\n</div>\n\n"
|
| 441 |
|
| 442 |
-
# for subsection in section.get('Subsections', []):
|
| 443 |
-
# subsection_number = subsection['PageNumber']
|
| 444 |
-
# subsection_title = subsection['Title']
|
| 445 |
-
# markdown += f"<h3 id='{cls.slugify(subsection_title)}' style='color: #34495e;'>{subsection_number} {subsection_title}</h3>\n\n"
|
| 446 |
-
# markdown += f"<div style='color: #34495e; margin-bottom: 20px;'>\n\n{subsection['Content']}\n\n</div>\n\n"
|
| 447 |
-
|
| 448 |
markdown += "</div>"
|
| 449 |
return markdown
|
| 450 |
|
|
|
|
| 402 |
def slugify(text: str) -> str:
|
| 403 |
return re.sub(r'\W+', '-', text.lower())
|
| 404 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 405 |
@classmethod
|
| 406 |
def convert_to_markdown(cls, document: Dict) -> str:
|
| 407 |
markdown = "<div style='text-align: center; padding-top: 33vh;'>\n\n"
|
|
|
|
| 410 |
markdown += f"<p style='color: #95a5a6;'>Version {document['Version']} | {document['Date']}</p>\n\n"
|
| 411 |
markdown += "</div>\n\n"
|
| 412 |
|
| 413 |
+
# Generate Table of Contents
|
| 414 |
+
markdown += "<div style='page-break-before: always;'></div>\n\n"
|
| 415 |
+
markdown += "<h2 style='color: #2c3e50; text-align: center;'>Table of Contents</h2>\n\n"
|
| 416 |
+
markdown += "<nav style='background-color: #f8f9fa; padding: 20px; border-radius: 5px; line-height: 1.6;'>\n\n"
|
| 417 |
|
| 418 |
+
for section in document['Pages']:
|
| 419 |
+
section_number = section['PageNumber']
|
| 420 |
+
section_title = section['Title']
|
| 421 |
+
markdown += f"<p><a href='#{cls.slugify(section_title)}' style='color: #3498db; text-decoration: none;'>{section_number}. {section_title}</a></p>\n\n"
|
| 422 |
+
|
| 423 |
+
for subsection in section.get('Subsections', []):
|
| 424 |
+
subsection_number = subsection['PageNumber']
|
| 425 |
+
subsection_title = subsection['Title']
|
| 426 |
+
markdown += f"<p style='margin-left: 20px;'><a href='#{cls.slugify(subsection_title)}' style='color: #2980b9; text-decoration: none;'>{subsection_number} {subsection_title}</a></p>\n\n"
|
| 427 |
+
|
| 428 |
+
markdown += "</nav>\n\n"
|
| 429 |
+
|
| 430 |
+
# Generate Content
|
| 431 |
markdown += "<div style='max-width: 800px; margin: 0 auto; font-family: \"Segoe UI\", Arial, sans-serif; line-height: 1.6;'>\n\n"
|
| 432 |
|
| 433 |
+
for section in document['Pages']:
|
| 434 |
markdown += "<div style='page-break-before: always;'></div>\n\n"
|
| 435 |
section_number = section['PageNumber']
|
| 436 |
section_title = section['Title']
|
| 437 |
markdown += f"<h2 id='{cls.slugify(section_title)}' style='color: #2c3e50; border-bottom: 1px solid #bdc3c7; padding-bottom: 5px;'>{section_number}. {section_title}</h2>\n\n"
|
| 438 |
markdown += f"<div style='color: #34495e; margin-bottom: 20px;'>\n\n{section['Content']}\n\n</div>\n\n"
|
| 439 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 440 |
markdown += "</div>"
|
| 441 |
return markdown
|
| 442 |
|