Skip to content

Commit

Permalink
typogrify: Do not remove space between comma and fraction.
Browse files Browse the repository at this point in the history
  • Loading branch information
gvtulder authored and acabal committed Sep 21, 2024
1 parent 2be6ecb commit 99f028a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion se/typography.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def typogrify(xhtml: str, smart_quotes: bool = True) -> str:
xhtml = regex.sub(r"\b(?<!/)([0-9]{1,3}|[0-9]{5,})/\b([0-9]{1,3}|[0-9]{5,})(?!/)\b", lambda result: _number_to_fraction(result.group(0)), xhtml)

# Remove spaces between whole numbers and fractions
xhtml = regex.sub(r"([0-9,]+)\s+([¼½¾⅐⅑⅒⅓⅔⅕⅖⅗⅘⅙⅚⅛⅜⅝⅞]|[⁰¹²³⁴⁵⁶⁷⁸⁹]+⁄[₀₁₂₃₄₅₆₇₈₉]+)", r"\1\2", xhtml)
xhtml = regex.sub(r"([0-9])\s+([¼½¾⅐⅑⅒⅓⅔⅕⅖⅗⅘⅙⅚⅛⅜⅝⅞]|[⁰¹²³⁴⁵⁶⁷⁸⁹]+⁄[₀₁₂₃₄₅₆₇₈₉]+)", r"\1\2", xhtml)

# Use the Unicode Minus glyph (U+2212) for negative numbers
xhtml = regex.sub(r"([\s>])\-([0-9,]+)", r"\1−\2", xhtml)
Expand Down
2 changes: 2 additions & 0 deletions tests/draft_commands/typogrify/test-1/golden/typogrify.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
<li>123¾</li>
<li>123⅚</li>
<li>123¹⁄₈₀₀</li>
<li>1,234¼</li>
<li>keep space after comma, ¹⁄₈₀₀</li>
</ul>
</section>
</body>
Expand Down
2 changes: 2 additions & 0 deletions tests/draft_commands/typogrify/test-1/in/typogrify.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
<li>123 ¾</li>
<li>123⅚</li>
<li>123¹⁄₈₀₀</li>
<li>1,234 ¼</li>
<li>keep space after comma, ¹⁄₈₀₀</li>
</ul>
</section>
</body>
Expand Down

0 comments on commit 99f028a

Please sign in to comment.