Skip to content

Commit 31b8a4b

Browse files
author
Ned Batchelder
committed
fix: don't include anchors in GitHub releases. #53
1 parent 56297c7 commit 31b8a4b

File tree

6 files changed

+28
-1
lines changed

6 files changed

+28
-1
lines changed
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Fixed
2+
.....
3+
4+
- Anchors in the changelog were being included in the previous sections when
5+
creating GitHub releases. This has been fixed, closing `issue 53`_.
6+
7+
.. _issue 53: https://github.com/nedbat/scriv/issues/53

src/scriv/format_md.py

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ def parse_text(
2727
if re.search(r"^\s*<!--.*-->$", line):
2828
# A one-line comment, skip it.
2929
continue
30+
if re.search(r"""^<a id=(['"])[-.\w]+\1></a>$""", line):
31+
# An anchor, we don't need those.
32+
continue
3033
if re.search(r"^\s*<!--", line):
3134
in_comment = True
3235
continue

src/scriv/format_rst.py

+9
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ def _is_comment(self, line: str) -> bool:
4646
else:
4747
return False
4848

49+
def _is_anchor(self, line: str) -> bool:
50+
"""
51+
Determine if a line is an anchor.
52+
"""
53+
return bool(re.search(r"^.. _[-.\w]+:$", line))
54+
4955
def parse_text(
5056
self, text: str
5157
) -> SectionDict: # noqa: D102 (inherited docstring)
@@ -66,6 +72,9 @@ def parse_text(
6672
# Comment, do nothing.
6773
continue
6874

75+
if self._is_anchor(line):
76+
continue
77+
6978
if self._is_underline(line):
7079
if section_char is None or line[0] == section_char:
7180
# Section underline. Previous line was the heading.

src/scriv/github.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,7 @@ def update_release(
9494
See create_release for the accepted keys.
9595
"""
9696
logger.info(f"Updating release {release_data['name']}")
97-
resp = requests.patch(release["url"], json=release_data, headers=auth_headers())
97+
resp = requests.patch(
98+
release["url"], json=release_data, headers=auth_headers()
99+
)
98100
check_ok(resp)

tests/test_format_md.py

+2
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@
151151
"""\
152152
(prelude)
153153
154+
<a id='sect-one.1'></a>
154155
## Section one
155156
156157
### subhead
@@ -161,6 +162,7 @@
161162
162163
Also sub
163164
165+
<a id='sect-two.2'></a>
164166
## Section two
165167
166168
In section two.

tests/test_format_rst.py

+4
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,16 @@
131131
# RST syntax is intricate. We understand a subset of it.
132132
pytest.param(
133133
"""\
134+
.. _fixed.1:
135+
134136
Fixed
135137
.....
136138
- This thing was fixed: `issue 42`_.
137139
138140
.. _issue 42: https://github.com/thing/issue/42
139141
142+
.. _added:
143+
140144
Added
141145
.....
142146

0 commit comments

Comments
 (0)