Browse Source

Fix handling of self-closing tags (closes #31)

tags/v0.3
Ben Kurtovic 11 years ago
parent
commit
61fc5b5eab
3 changed files with 7 additions and 6 deletions
  1. +3
    -2
      mwparserfromhell/nodes/tag.py
  2. +2
    -2
      mwparserfromhell/parser/builder.py
  3. +2
    -2
      mwparserfromhell/parser/tokenizer.py

+ 3
- 2
mwparserfromhell/nodes/tag.py View File

@@ -79,8 +79,9 @@ class Tag(TagDefinitions, Node):
if attr.value:
for child in getter(attr.value):
yield attr.value, child
for child in getter(self.contents):
yield self.contents, child
if self.contents:
for child in getter(self.contents):
yield self.contents, child

def __strip__(self, normalize, collapse):
if self.type in self.TAGS_VISIBLE:


+ 2
- 2
mwparserfromhell/parser/builder.py View File

@@ -191,8 +191,8 @@ class Builder(object):
self._push()
elif isinstance(token, tokens.TagAttrQuote):
quoted = True
elif isinstance(token, (tokens.TagAttrStart,
tokens.TagCloseOpen)):
elif isinstance(token, (tokens.TagAttrStart, tokens.TagCloseOpen,
tokens.TagCloseSelfclose)):
self._tokens.append(token)
if name is not None:
return Attribute(name, self._pop(), quoted, padding)


+ 2
- 2
mwparserfromhell/parser/tokenizer.py View File

@@ -26,8 +26,8 @@ import re

from . import contexts
from . import tokens
from ..nodes.tag import Tag
from ..compat import htmlentities
from ..nodes.tag import Tag

__all__ = ["Tokenizer"]

@@ -431,7 +431,7 @@ class Tokenizer(object):
try:
return Tag.TRANSLATIONS[text]
except KeyError:
self._fail_route()
return Tag.TAG_UNKNOWN

def _actually_close_tag_opening(self):
"""Handle cleanup at the end of a opening tag.


Loading…
Cancel
Save