瀏覽代碼

Support parser-blacklisted tags like <nowiki>

tags/v0.3
Ben Kurtovic 11 年之前
父節點
當前提交
fb92012fcb
共有 1 個文件被更改,包括 16 次插入1 次删除
  1. +16
    -1
      mwparserfromhell/parser/tokenizer.py

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

@@ -459,7 +459,9 @@ class Tokenizer(object):
elif this == ">" and can_exit:
self._handle_tag_close_open(data, tokens.TagCloseOpen)
self._context = contexts.TAG_BODY
return self._parse(push=False)
if is_parsable(self._stack[1].text):
return self._parse(push=False)
return self._handle_blacklisted_tag()
elif this == "/" and next == ">" and can_exit:
self._handle_tag_close_open(data, tokens.TagCloseSelfclose)
return self._pop()
@@ -559,6 +561,19 @@ class Tokenizer(object):
else:
self._emit_text(text)

def _handle_blacklisted_tag(self):
"""Handle the body of an HTML tag that is parser-blacklisted."""
while True:
this, next = self._read(), self._read(1)
self._head += 1
if this is self.END:
self._fail_route()
elif this == "<" and next == "/":
self._handle_tag_open_close()
return self._parse(push=False)
else:
self._emit_text(this)

def _handle_tag_close_open(self, data, token):
"""Handle the closing of a open tag (``<foo>``)."""
if data.context & (data.CX_ATTR_NAME | data.CX_ATTR_VALUE):


Loading…
取消
儲存