Skip to content

Commit

Permalink
fix(plain_text): use parsed object instead of self
Browse files Browse the repository at this point in the history
closes #130
  • Loading branch information
5j9 committed Mar 19, 2024
1 parent ab5033a commit ffd3b53
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 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 ``plain_text`` causing ``IndexError`` when using a custom function to replace ``templates``/``parser_functions``.

v0.55.9
-------
Expand Down
9 changes: 9 additions & 0 deletions tests/wikitext/test_plain_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,12 @@ def test_tag_containing_comment_with_no_end(): # 126
)
del parsed.wikilinks[0][:]
assert parsed.plain_text().strip() == ''


def test_on_list_with_replace_template_function(): # 130
assert (
parse('\n#:{{a}}')
.get_lists()[0]
.plain_text(replace_templates=lambda t: t.name)
== '#:a'
)
4 changes: 2 additions & 2 deletions wikitextparser/_wikitext.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ def remove(b: int, e: int):
remove(b, e)

if callable(replace_templates):
for template in self.templates:
for template in parsed.templates:
b, e = template._span_data[:2] # noqa
if lst[b] is None: # overwritten
continue
Expand All @@ -688,7 +688,7 @@ def remove(b: int, e: int):
remove(b, e)

if callable(replace_parser_functions):
for pf in self.parser_functions:
for pf in parsed.parser_functions:
b, e = pf._span_data[:2]
if lst[b] is None: # already overwritten
continue
Expand Down

0 comments on commit ffd3b53

Please sign in to comment.