Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/guiguts/html_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,8 @@ def find_illo_markup(self) -> None:
caption = re.sub("</?p>", "", caption)
caption = re.sub("^\n+", "", caption)
caption = re.sub("\n$", "", caption)
caption = re.sub("\n", RETURN_ARROW, caption)
caption = re.sub("\n *", RETURN_ARROW, caption)
caption = re.sub("^ +", "", caption)
self.caption_textvariable.set(caption)
# Clear alt text, ready for user to type in required string
self.alt_textvariable.set("")
Expand Down Expand Up @@ -475,10 +476,17 @@ def convert_to_html(self, auto_illus: bool) -> None:
if preferences.get(PrefKey.HTML_IMAGE_CAPTION_P):
caption = f"<p>{caption.lstrip()}</p>"
caption = re.sub(
f"{RETURN_ARROW}{RETURN_ARROW} *", "</p>\n <p>", caption
f"{RETURN_ARROW}{RETURN_ARROW} *", "</p>\n<p>", caption
)
caption = re.sub(RETURN_ARROW, "\n ", f" {caption}")
caption = re.sub(RETURN_ARROW, "\n", f" {caption}")
caption = re.sub("^ +", "", caption)
caption = re.sub("\n +", "\n", caption)
# Add space at start of each line
caption = re.sub("^", " ", caption)
caption = re.sub("\n", "\n ", caption)
caption = f" <figcaption>\n{caption}\n </figcaption>\n"
# If caption already had p markup, e.g. for right justify, avoid double markup
caption = caption.replace("<p><p", "<p")
# Now alt text - escape any double quotes
alt = self.alt_textvariable.get().replace('"', "&quot;")
alt = f' alt="{alt}"'
Expand Down