Update app.py
Browse files
app.py
CHANGED
@@ -104,6 +104,7 @@ def create_pdf_tab(default_markdown):
|
|
104 |
styles = getSampleStyleSheet()
|
105 |
story = []
|
106 |
spacer_height = 10
|
|
|
107 |
pdf_content, total_lines = markdown_to_pdf_content(markdown_text, plain_text_mode)
|
108 |
|
109 |
item_font_size = base_font_size
|
@@ -124,7 +125,14 @@ def create_pdf_tab(default_markdown):
|
|
124 |
current_line_count = 0
|
125 |
current_column = 0
|
126 |
|
127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
if current_line_count >= lines_per_column and current_column < num_columns - 1:
|
129 |
current_column += 1
|
130 |
current_line_count = 0
|
@@ -134,7 +142,9 @@ def create_pdf_tab(default_markdown):
|
|
134 |
column_cells = [[] for _ in range(num_columns)]
|
135 |
for col_idx, column in enumerate(columns):
|
136 |
for item in column:
|
137 |
-
if isinstance(item,
|
|
|
|
|
138 |
text = item.replace('<b>', '').replace('</b>', '')
|
139 |
column_cells[col_idx].append(Paragraph(apply_emoji_font(text, selected_font_name), section_style))
|
140 |
else:
|
@@ -187,7 +197,7 @@ def create_pdf_tab(default_markdown):
|
|
187 |
else:
|
188 |
st.info("Download the PDF to view it locally.")
|
189 |
|
190 |
-
#
|
191 |
with st.sidebar:
|
192 |
st.download_button(label="Download PDF", data=pdf_bytes, file_name="deities_guide.pdf", mime="application/pdf")
|
193 |
|
|
|
104 |
styles = getSampleStyleSheet()
|
105 |
story = []
|
106 |
spacer_height = 10
|
107 |
+
section_spacer_height = 15 # Extra spacing before numbered sections
|
108 |
pdf_content, total_lines = markdown_to_pdf_content(markdown_text, plain_text_mode)
|
109 |
|
110 |
item_font_size = base_font_size
|
|
|
125 |
current_line_count = 0
|
126 |
current_column = 0
|
127 |
|
128 |
+
# Regex to detect numbered sections (e.g., "1. ", "2. ")
|
129 |
+
number_pattern = re.compile(r'^\d+\.\s')
|
130 |
+
|
131 |
+
for i, item in enumerate(pdf_content):
|
132 |
+
# Add extra spacing before numbered sections (but not the first one)
|
133 |
+
if i > 0 and number_pattern.match(item):
|
134 |
+
columns[current_column].append(Spacer(1, section_spacer_height))
|
135 |
+
|
136 |
if current_line_count >= lines_per_column and current_column < num_columns - 1:
|
137 |
current_column += 1
|
138 |
current_line_count = 0
|
|
|
142 |
column_cells = [[] for _ in range(num_columns)]
|
143 |
for col_idx, column in enumerate(columns):
|
144 |
for item in column:
|
145 |
+
if isinstance(item, Spacer):
|
146 |
+
column_cells[col_idx].append(item)
|
147 |
+
elif isinstance(item, str) and item.startswith('<b>'):
|
148 |
text = item.replace('<b>', '').replace('</b>', '')
|
149 |
column_cells[col_idx].append(Paragraph(apply_emoji_font(text, selected_font_name), section_style))
|
150 |
else:
|
|
|
197 |
else:
|
198 |
st.info("Download the PDF to view it locally.")
|
199 |
|
200 |
+
# "Download PDF" in sidebar
|
201 |
with st.sidebar:
|
202 |
st.download_button(label="Download PDF", data=pdf_bytes, file_name="deities_guide.pdf", mime="application/pdf")
|
203 |
|