Skip to content

chore: first pass#3200

Draft
stevekaplan123 wants to merge 7 commits intomasterfrom
bug/sc-40416/-research-copy-and-paste-from-ios-creates-odd
Draft

chore: first pass#3200
stevekaplan123 wants to merge 7 commits intomasterfrom
bug/sc-40416/-research-copy-and-paste-from-ios-creates-odd

Conversation

@stevekaplan123
Copy link
Copy Markdown
Contributor

@stevekaplan123 stevekaplan123 commented Mar 31, 2026

Description

When someone shares a link to a text on Sefaria, many apps show a preview card with a generated image of the passage. In some cases that image showed odd fragments like   or   instead of normal spaces.
On newer server setups, generating that image could also fail outright because the graphics library we use stopped supporting an older API. When that happened, the site fell back to a generic logo-only image instead of the passage.
This change cleans the text before drawing it and updates the code to work with current versions of the image library so previews look right and generate reliably.


Code Changes

File: sefaria/image_generator.py

cleanup_and_format_text

  • html.unescape after stripping HTML tags so named/numeric entities ( ,  , &#…;, etc.) become real characters instead of literal &…; strings in the PNG.
  • Unicode space normalization: map NBSP, thin/em/hair spaces, figure space, narrow NBSP, medium math space (\u00a0, \u2000\u200a, \u202f, \u205f) to ASCII space for consistent PIL layout.
  • Strip zero-width / invisible chars: \u200b\u200d, \u2060, \ufeff (covers common ZWSP/ZWNJ/ZWJ/word-joiner/BOM cases).
  • No text: return "" early to avoid errors downstream.

This comment was marked as outdated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants