Update app.py
Browse files
app.py
CHANGED
@@ -124,17 +124,17 @@ def apply_emoji_font(text, emoji_font):
|
|
124 |
# Keep tags unchanged
|
125 |
result.append(segment)
|
126 |
else:
|
127 |
-
# Apply font to
|
128 |
parts = []
|
129 |
last_pos = 0
|
130 |
for match in emoji_pattern.finditer(segment):
|
131 |
start, end = match.span()
|
132 |
if last_pos < start:
|
133 |
-
parts.append(f'<font face="
|
134 |
parts.append(replace_emoji(match))
|
135 |
last_pos = end
|
136 |
if last_pos < len(segment):
|
137 |
-
parts.append(f'<font face="
|
138 |
result.append(''.join(parts))
|
139 |
|
140 |
return ''.join(result)
|
@@ -170,10 +170,9 @@ def markdown_to_pdf_content(markdown_text, render_with_bold, auto_bold_numbers,
|
|
170 |
|
171 |
line = detect_and_convert_links(line)
|
172 |
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
line = re.sub(r'\*([^*]+?)\*', r'<b>\1</b>', line)
|
177 |
|
178 |
if auto_bold_numbers and is_numbered_line:
|
179 |
if not (line.startswith("<b>") and line.endswith("</b>")):
|
@@ -232,7 +231,7 @@ def create_pdf(markdown_text, base_font_size, render_with_bold, auto_bold_number
|
|
232 |
adjusted_font_size = int(col_width / (avg_line_chars / 10))
|
233 |
adjusted_font_size = max(min_font_size, adjusted_font_size)
|
234 |
item_style = ParagraphStyle(
|
235 |
-
'ItemStyle', parent=styles['Normal'], fontName="
|
236 |
fontSize=adjusted_font_size, leading=adjusted_font_size * 1.15, spaceAfter=1,
|
237 |
linkUnderline=True
|
238 |
)
|
@@ -243,7 +242,7 @@ def create_pdf(markdown_text, base_font_size, render_with_bold, auto_bold_number
|
|
243 |
linkUnderline=True
|
244 |
)
|
245 |
section_style = ParagraphStyle(
|
246 |
-
'SectionStyle', parent=styles['Heading2'], fontName="
|
247 |
textColor=colors.darkblue, fontSize=adjusted_font_size * 1.1, leading=adjusted_font_size * 1.32, spaceAfter=2,
|
248 |
linkUnderline=True
|
249 |
)
|
@@ -269,7 +268,7 @@ def create_pdf(markdown_text, base_font_size, render_with_bold, auto_bold_number
|
|
269 |
heading_style = ParagraphStyle(
|
270 |
f'Heading{level}Style',
|
271 |
parent=styles['Heading1'],
|
272 |
-
fontName="
|
273 |
textColor=colors.darkblue if level == 1 else (colors.black if level > 2 else colors.blue),
|
274 |
fontSize=adjusted_font_size * (1.6 - (level-1)*0.15),
|
275 |
leading=adjusted_font_size * (1.8 - (level-1)*0.15),
|
@@ -280,15 +279,11 @@ def create_pdf(markdown_text, base_font_size, render_with_bold, auto_bold_number
|
|
280 |
column_cells[col_idx].append(Paragraph(apply_emoji_font(heading_text, "NotoEmoji-Bold"), heading_style))
|
281 |
elif item.startswith("<b>") and item.endswith("</b>"):
|
282 |
content = item[3:-4].strip()
|
283 |
-
|
284 |
-
if number_pattern.match(content):
|
285 |
-
column_cells[col_idx].append(Paragraph(apply_emoji_font(content, "NotoEmoji-Bold"), numbered_bold_style))
|
286 |
-
else:
|
287 |
-
column_cells[col_idx].append(Paragraph(apply_emoji_font(content, "NotoEmoji-Bold"), section_style))
|
288 |
else:
|
289 |
-
column_cells[col_idx].append(Paragraph(apply_emoji_font(item, "
|
290 |
else:
|
291 |
-
column_cells[col_idx].append(Paragraph(apply_emoji_font(str(item), "
|
292 |
max_cells = max(len(cells) for cells in column_cells) if column_cells else 0
|
293 |
for cells in column_cells:
|
294 |
cells.extend([Paragraph("", item_style)] * (max_cells - len(cells)))
|
@@ -400,7 +395,7 @@ def create_crossfile_pdfs(source_pdf="TestSource.pdf", target_pdf="TestTarget.pd
|
|
400 |
|
401 |
create_base_pdf(source_pdf)
|
402 |
create_base_pdf(target_pdf)
|
403 |
-
add_bookmark_to_seven(
|
404 |
modify_source_pdf(source, target)
|
405 |
add_internal_link(source_pdf)
|
406 |
add_internal_link(target_pdf)
|
|
|
124 |
# Keep tags unchanged
|
125 |
result.append(segment)
|
126 |
else:
|
127 |
+
# Apply emoji font to all text to preserve emojis
|
128 |
parts = []
|
129 |
last_pos = 0
|
130 |
for match in emoji_pattern.finditer(segment):
|
131 |
start, end = match.span()
|
132 |
if last_pos < start:
|
133 |
+
parts.append(f'<font face="{emoji_font}">{segment[last_pos:start]}</font>')
|
134 |
parts.append(replace_emoji(match))
|
135 |
last_pos = end
|
136 |
if last_pos < len(segment):
|
137 |
+
parts.append(f'<font face="{emoji_font}">{segment[last_pos:]}</font>')
|
138 |
result.append(''.join(parts))
|
139 |
|
140 |
return ''.join(result)
|
|
|
170 |
|
171 |
line = detect_and_convert_links(line)
|
172 |
|
173 |
+
# Always preserve bold and emphasis formatting to ensure emoji rendering
|
174 |
+
line = re.sub(r'\*\*(.+?)\*\*', r'<b>\1</b>', line)
|
175 |
+
line = re.sub(r'\*([^*]+?)\*', r'<b>\1</b>', line)
|
|
|
176 |
|
177 |
if auto_bold_numbers and is_numbered_line:
|
178 |
if not (line.startswith("<b>") and line.endswith("</b>")):
|
|
|
231 |
adjusted_font_size = int(col_width / (avg_line_chars / 10))
|
232 |
adjusted_font_size = max(min_font_size, adjusted_font_size)
|
233 |
item_style = ParagraphStyle(
|
234 |
+
'ItemStyle', parent=styles['Normal'], fontName="NotoEmoji-Bold",
|
235 |
fontSize=adjusted_font_size, leading=adjusted_font_size * 1.15, spaceAfter=1,
|
236 |
linkUnderline=True
|
237 |
)
|
|
|
242 |
linkUnderline=True
|
243 |
)
|
244 |
section_style = ParagraphStyle(
|
245 |
+
'SectionStyle', parent=styles['Heading2'], fontName="NotoEmoji-Bold",
|
246 |
textColor=colors.darkblue, fontSize=adjusted_font_size * 1.1, leading=adjusted_font_size * 1.32, spaceAfter=2,
|
247 |
linkUnderline=True
|
248 |
)
|
|
|
268 |
heading_style = ParagraphStyle(
|
269 |
f'Heading{level}Style',
|
270 |
parent=styles['Heading1'],
|
271 |
+
fontName="NotoEmoji-Bold",
|
272 |
textColor=colors.darkblue if level == 1 else (colors.black if level > 2 else colors.blue),
|
273 |
fontSize=adjusted_font_size * (1.6 - (level-1)*0.15),
|
274 |
leading=adjusted_font_size * (1.8 - (level-1)*0.15),
|
|
|
279 |
column_cells[col_idx].append(Paragraph(apply_emoji_font(heading_text, "NotoEmoji-Bold"), heading_style))
|
280 |
elif item.startswith("<b>") and item.endswith("</b>"):
|
281 |
content = item[3:-4].strip()
|
282 |
+
column_cells[col_idx].append(Paragraph(apply_emoji_font(content, "NotoEmoji-Bold"), numbered_bold_style))
|
|
|
|
|
|
|
|
|
283 |
else:
|
284 |
+
column_cells[col_idx].append(Paragraph(apply_emoji_font(item, "NotoEmoji-Bold"), item_style))
|
285 |
else:
|
286 |
+
column_cells[col_idx].append(Paragraph(apply_emoji_font(str(item), "NotoEmoji-Bold"), item_style))
|
287 |
max_cells = max(len(cells) for cells in column_cells) if column_cells else 0
|
288 |
for cells in column_cells:
|
289 |
cells.extend([Paragraph("", item_style)] * (max_cells - len(cells)))
|
|
|
395 |
|
396 |
create_base_pdf(source_pdf)
|
397 |
create_base_pdf(target_pdf)
|
398 |
+
add_bookmark_to_seven(target_pdf)
|
399 |
modify_source_pdf(source, target)
|
400 |
add_internal_link(source_pdf)
|
401 |
add_internal_link(target_pdf)
|