瀏覽代碼

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

tags/v0.3
Ben Kurtovic 11 年之前
父節點
當前提交
61fc5b5eab
共有 3 個檔案被更改,包括 7 行新增6 行删除
  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 查看文件

@@ -79,8 +79,9 @@ class Tag(TagDefinitions, Node):
if attr.value: if attr.value:
for child in getter(attr.value): for child in getter(attr.value):
yield attr.value, child 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): def __strip__(self, normalize, collapse):
if self.type in self.TAGS_VISIBLE: if self.type in self.TAGS_VISIBLE:


+ 2
- 2
mwparserfromhell/parser/builder.py 查看文件

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


+ 2
- 2
mwparserfromhell/parser/tokenizer.py 查看文件

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


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


__all__ = ["Tokenizer"] __all__ = ["Tokenizer"]


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


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


Loading…
取消
儲存