Skip to content

Commit

Permalink
fix(_ext_link_shadow): subspans's indexes are relative to lststr0
Browse files Browse the repository at this point in the history
fixes #137
  • Loading branch information
5j9 committed Jun 28, 2024
1 parent 93eb938 commit 35d9398
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
7 changes: 3 additions & 4 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
..
Unreleased
----------
*
Unreleased
----------
* Fixed a bug in detecting the text of an external link. (#137)

v0.55.13
--------
Expand Down
6 changes: 6 additions & 0 deletions tests/wikitext/test_plain_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,9 @@ def test_on_list_with_replace_template_function(): # 130
.plain_text(replace_templates=lambda t: t.name)
== '#:a'
)


def test_external_starting_with_comment():
text = "''[https://<!---->x.com/ x]''"
parsed = parse(text)
assert parsed.plain_text() == 'x'
6 changes: 3 additions & 3 deletions wikitextparser/_wikitext.py
Original file line number Diff line number Diff line change
Expand Up @@ -1194,14 +1194,14 @@ def get_italics(self, recursive=True) -> List['Italic']:
)

@property
def _ext_link_shadow(self):
def _ext_link_shadow(self) -> memoryview:
"""Replace the invalid chars of SPAN_PARSER_TYPES with b'_'.
For comments, all characters are replaced, but for ('Template',
'ParserFunction', 'Parameter') only invalid characters are replaced.
"""
ss, se, _, _ = self._span_data
byte_array = bytearray(self._lststr[0][ss:se], 'ascii', 'replace')
byte_array = bytearray(self._lststr[0], 'ascii', 'replace')
subspans = self._subspans
for s, e, _, _ in subspans('Comment'):
byte_array[s:e] = (e - s) * b'_'
Expand All @@ -1210,7 +1210,7 @@ def _ext_link_shadow(self):
for type_ in 'Template', 'ParserFunction', 'Parameter':
for s, e, _, _ in subspans(type_):
byte_array[s:e] = INVALID_EXT_CHARS_SUB(b' ', byte_array[s:e])
return byte_array
return memoryview(byte_array)[ss:se]

@property
def external_links(self) -> List['ExternalLink']:
Expand Down

0 comments on commit 35d9398

Please sign in to comment.