| 1 |
"""Data transformation helpers.""" |
| 2 |
|
| 3 |
|
| 4 |
def escape_project_version_rst_substitution(version: str) -> str: |
| 5 |
"""Prepend an escaped whitespace before RST substitution.""" |
| 6 |
if not version.startswith('|') or version.count('|') <= 1: |
| 7 |
return version |
| 8 |
|
| 9 |
# A corner case exists when the towncrier config has something like |
| 10 |
# `v{version}` in the title format **and** the directive target |
| 11 |
# argument starts with a substitution like `|release|`. And so |
| 12 |
# when combined, they produce a v|release|` causing RST to not |
| 13 |
# substitute the `|release|` part. But adding an escaped space |
| 14 |
# solves this: that escaped space renders as an empty string and |
| 15 |
# the substitution gets processed properly so the result would |
| 16 |
# be something like `v1.0` as expected. |
| 17 |
return rf'\ {version}' |