Skip to content

Commit dbeb782

Browse files
authored
Merge pull request #83 from maresb/fix-pypi-readme
Fix broken links in PyPI README
2 parents a88fb76 + 79bd716 commit dbeb782

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

pyproject.toml

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
[build-system]
2-
requires = ["hatchling >=1.11.1,<2.0.0", "hatch-vcs >=0.3.0,<0.4"]
2+
requires = ["hatchling >=1.11.1,<2.0.0", "hatch-vcs >=0.3.0,<0.4", "hatch-fancy-pypi-readme"]
33
build-backend = "hatchling.build"
44

55
[project]
66
name = "labelle"
77
description = "Open-source label printing software"
8-
readme = "README.md"
98
url = "https://github.com/labelle-org/labelle"
109
authors = [{name = "Sebastian J. Bronner", email = "[email protected]"}]
1110
maintainers = [
@@ -35,7 +34,7 @@ classifiers = [
3534
"Programming Language :: Python :: 3.12",
3635
"Topic :: Printing",
3736
]
38-
dynamic = ["version"]
37+
dynamic = ["version", "readme"]
3938
requires-python = ">=3.8,<4"
4039

4140
[project.optional-dependencies]
@@ -66,6 +65,30 @@ version-file = "src/labelle/_version.py"
6665
[tool.hatch.build.targets.wheel]
6766
packages = ["src/labelle"]
6867

68+
# <https://github.com/hynek/hatch-fancy-pypi-readme>
69+
[tool.hatch.metadata.hooks.fancy-pypi-readme]
70+
content-type = "text/markdown"
71+
72+
[[tool.hatch.metadata.hooks.fancy-pypi-readme.fragments]]
73+
path = "README.md"
74+
75+
[[tool.hatch.metadata.hooks.fancy-pypi-readme.substitutions]]
76+
# Image links should go to the raw content on GitHub
77+
# <https://stackoverflow.com/a/46875147>
78+
pattern = '\[(.*?)\]\(((?!https?://)\S+\.(png|jpe?g|svg|gif))\)'
79+
replacement = '[\1](https://raw.githubusercontent.com/labelle-org/labelle/main/\g<2>)'
80+
81+
[[tool.hatch.metadata.hooks.fancy-pypi-readme.substitutions]]
82+
# Handle also HTML image tags
83+
pattern = '''(<img\b[^>]*\bsrc=)(['"])((?!https?://)[^'"]+)(['"][^>]*>)'''
84+
replacement = '<img src="https://raw.githubusercontent.com/labelle-org/labelle/main/\g<3>\g<4>'
85+
86+
[[tool.hatch.metadata.hooks.fancy-pypi-readme.substitutions]]
87+
# Remaining non-image relative links map to the normal absolute GitHub URL
88+
# <https://stackoverflow.com/a/46875147>
89+
pattern = '\[(.*?)\]\(((?!https?://)\S+)\)'
90+
replacement = '[\1](https://github.com/labelle-org/labelle/tree/main/\g<2>)'
91+
6992
[tool.tox]
7093
legacy_tox_ini = """
7194
[tox]

0 commit comments

Comments
 (0)