Skip to content

Commit 611f97b

Browse files
committed
chore(START_TAG_PATTERN): remove self_closing group
1 parent 6807d16 commit 611f97b

3 files changed

Lines changed: 9 additions & 17 deletions

File tree

tests/test_tag.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,23 @@ def test_start_tag_patterns():
2121
assert start_tag_finder(b'<b>').groupdict() == {
2222
'name': b'b', 'attr': None, 'quote': None,
2323
'start_tag': b'<b>', 'attr_name': None,
24-
'self_closing': None, 'attr_value': None, 'attr_insert': b'',}
24+
'attr_value': None, 'attr_insert': b'',}
2525
assert start_tag_finder(b'<b t>').groupdict() == {
2626
'name': b'b', 'attr': b' t', 'quote': None,
2727
'start_tag': b'<b t>', 'attr_name': b't', 'attr_value': b'',
28-
'self_closing': None, 'attr_insert': b'',}
28+
'attr_insert': b'',}
2929
assert start_tag_finder(b'<div value=yes>').groupdict() == {
3030
'name': b'div', 'attr': b' value=yes', 'quote': None,
3131
'start_tag': b'<div value=yes>', 'attr_name': b'value',
32-
'attr_value': b'yes', 'self_closing': None, 'attr_insert': b'',}
32+
'attr_value': b'yes', 'attr_insert': b'',}
3333
assert start_tag_finder(b"<div class='body'>").groupdict() == {
3434
'name': b'div', 'attr': b" class='body'", 'quote': b"'",
3535
'start_tag': b"<div class='body'>", 'attr_name': b'class',
36-
'attr_value': b'body', 'self_closing': None, 'attr_insert': b'',}
37-
# This is not standard HTML5, but could be useful to have.
38-
# ae(
39-
# START_TAG_MATCH('<s style=>').groupdict(),
40-
# {'name': 's', 'attr': 'style=', 'quote': None,
41-
# 'start': '<s style=>', 'attr_name': 'style', 'attr_value': ''
42-
# 'self_closing': None}
43-
# )
36+
'attr_value': b'body', 'attr_insert': b'',}
4437
assert start_tag_finder(b"<table a1=v1 a2=v2>").capturesdict() == {
4538
'attr_name': [b'a1', b'a2'], 'start_tag': [b'<table a1=v1 a2=v2>'],
4639
'attr': [b' a1=v1', b' a2=v2'], 'quote': [],
47-
'attr_value': [b'v1', b'v2'], 'self_closing': [],
40+
'attr_value': [b'v1', b'v2'],
4841
'name': [b'table'], 'attr_insert': [b'']}
4942

5043

wikitextparser/_spans.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,7 @@
173173
START_TAG_PATTERN = ( # noqa
174174
rb'(?<start_tag>'
175175
rb'<{name}' + ATTRS_PATTERN +
176-
rb'[' + SPACE_CHARS + rb']*+'
177-
rb'(?:(?<self_closing>/[' + SPACE_CHARS + b']*+>)|>)'
176+
rb'[' + SPACE_CHARS + rb']*+>'
178177
rb')')
179178
HTML_START_TAG_FINDITER = regex_compile(
180179
START_TAG_PATTERN.replace(b'{name}', _HTML_TAG_NAME, 1)).finditer

wikitextparser/_wikitext.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ def remove(b: int, e: int):
606606
if callable(replace_parser_functions):
607607
for pf in self.parser_functions:
608608
b, e = pf._span_data[:2]
609-
if lst[b] is None: # overwrriten
609+
if lst[b] is None: # already overwritten
610610
continue
611611
lst[b] = replace_parser_functions(pf)
612612
remove(b + 1, e)
@@ -1350,8 +1350,8 @@ def get_tags(self, name=None) -> List['Tag']:
13501350
span_tuple_to_span_get = {(s[0], s[1]): s for s in spans}.get
13511351
spans_append = spans.append
13521352
for start_match in reversed_start_matches:
1353-
if start_match['self_closing']:
1354-
# Don't look for the end tag
1353+
if start_match[0].rstrip(b' \t\n>')[-1] == 47: # ord('/') == 47
1354+
# Self-closing tag. Don't look for the end tag.
13551355
ms, me = start_match.span()
13561356
span = [ss + ms, ss + me, None, shadow_copy[ms:me]]
13571357
else:

0 commit comments

Comments
 (0)