| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- import os
- import re
- import fitz
- from markdown_pdf import MarkdownPdf, Section
- docs_dir = r"c:/Users/lanfr144/Documents/DOPRO1/Antigravity/Food/docs"
- md_file = os.path.join(docs_dir, "Installation_Guide.md")
- with open(md_file, "r", encoding="utf-8") as f:
- md_content = f.read()
- # Clean paths
- root_dir = r"c:/Users/lanfr144/Documents/DOPRO1/Antigravity/Food"
- md_content = md_content.replace("file:///" + root_dir + "/docs/", "")
- md_content = md_content.replace("file:///" + root_dir + "/", "../")
- # Try WITH <br/> replacement
- md_content_br = re.sub(r'(```[a-zA-Z0-9_-]*\n[\s\S]*?\n```)', r'\1\n<br/>', md_content)
- user_css = """
- * {
- color: #1a1a1a !important;
- }
- body {
- font-family: 'Helvetica', 'Arial', sans-serif !important;
- color: #1a1a1a !important;
- background-color: #ffffff !important;
- }
- h1, h2, h3, h4, h5, h6, h1 *, h2 *, h3 *, h4 *, h5 *, h6 * {
- color: #000000 !important;
- margin-top: 18px !important;
- margin-bottom: 8px !important;
- }
- pre {
- background-color: #f8f9fa !important;
- border: 1px solid #e9ecef !important;
- padding: 2px !important;
- margin-top: 8px !important;
- margin-bottom: 16px !important;
- border-radius: 3px !important;
- font-family: 'Courier New', 'Courier', monospace !important;
- font-size: 10pt !important;
- white-space: pre-wrap !important;
- word-break: break-all !important;
- }
- pre code, pre * {
- font-family: 'Courier New', 'Courier', monospace !important;
- font-size: 10pt !important;
- color: #212529 !important;
- background-color: #f8f9fa !important;
- white-space: pre-wrap !important;
- word-break: break-all !important;
- }
- code {
- font-family: 'Courier New', 'Courier', monospace !important;
- font-size: 10pt !important;
- color: #b02a37 !important;
- background-color: #f8f9fa !important;
- padding: 2px 4px !important;
- border-radius: 3px !important;
- white-space: pre-wrap !important;
- word-break: break-all !important;
- }
- a, a * {
- color: #0d6efd !important;
- }
- blockquote, blockquote * {
- color: #555555 !important;
- border-left: 4px solid #ccc !important;
- padding-left: 10px !important;
- }
- table, tr, td, th, table * {
- color: #1a1a1a !important;
- border-color: #cccccc !important;
- }
- th {
- background-color: #f2f2f2 !important;
- }
- ul, li {
- list-style-type: disc !important;
- }
- """
- print("--- TESTING WITH <br/> ---")
- pdf_br = MarkdownPdf()
- pdf_br.add_section(Section(md_content_br, paper_size="A4", root=docs_dir), user_css=user_css)
- doc_br = pdf_br._make_doc()
- print(f"Total pages: {len(doc_br)}")
- print(f"Page 2 blocks count: {len(doc_br[1].get_text('blocks'))}")
- doc_br.close()
- print("\n--- TESTING WITH \\n\\n ---")
- # Try with \n\n instead
- md_content_nn = re.sub(r'(```[a-zA-Z0-9_-]*\n[\s\S]*?\n```)', r'\1\n\n', md_content)
- pdf_nn = MarkdownPdf()
- pdf_nn.add_section(Section(md_content_nn, paper_size="A4", root=docs_dir), user_css=user_css)
- doc_nn = pdf_nn._make_doc()
- print(f"Total pages: {len(doc_nn)}")
- print(f"Page 2 blocks count: {len(doc_nn[1].get_text('blocks'))}")
- doc_nn.close()
|