コード例 #1
0
ファイル: utoken.py プロジェクト: vprusa/mwlib
def _analyze_html_tag(t):
    text = t.text
    selfClosing = False
    if text.startswith(u"</"):
        name = text[2:-1]
        isEndToken = True
    elif text.endswith("/>"):
        name = text[1:-2]
        selfClosing = True
        isEndToken = False  # ???
    else:
        name = text[1:-1]
        isEndToken = False

    name, values = _split_tag(name)
    t.vlist = parseParams(values)
    name = name.lower()

    if name == 'br':
        isEndToken = False

    t.rawtagname = name
    t.tag_selfClosing = selfClosing
    t.tag_isEndToken = isEndToken
    if isEndToken:
        t.type = t.t_html_tag_end
コード例 #2
0
ファイル: utoken.py プロジェクト: aarddict/mwlib
def _analyze_html_tag(t):
    text = t.text
    selfClosing = False
    if text.startswith(u"</"):
        name = text[2:-1]
        isEndToken = True
    elif text.endswith("/>"):
        name = text[1:-2]
        selfClosing = True
        isEndToken = False # ???
    else:
        name = text[1:-1]
        isEndToken = False

    name, values = _split_tag(name)
    t.vlist = parseParams(values)
    name = name.lower()

    if name=='br':
        isEndToken = False

    t.rawtagname = name
    t.tag_selfClosing = selfClosing
    t.tag_isEndToken = isEndToken
    if isEndToken:
        t.type = t.t_html_tag_end
コード例 #3
0
 def find_modifier(self, row):
     children = row.children
     for i, x in enumerate(children):
         if x.type in (T.t_newline, T.t_break):
             mod = T.join_as_text(children[:i])
             #print "MODIFIER:", repr(mod)
             row.vlist = util.parseParams(mod)
             del children[:i]
             return
コード例 #4
0
    def find_modifier(self, cell):
        children = cell.children
        if not children:
            return
        for i, x in enumerate(children):
            t = children[i]
            if t.type == T.t_2box_open:
                break
            if t.type == T.t_special and t.text == "|":
                mod = T.join_as_text(children[:i])
                cell.vlist = util.parseParams(mod)

                del children[:i + 1]
                return
コード例 #5
0
ファイル: core.py プロジェクト: pediapress/mwlib
    def __init__(self, tokens, xopts):
        self.tagextensions = tagext.default_registry

        uniquifier = xopts.uniquifier
        if uniquifier is None:
            return

        i = 0
        while i < len(tokens):
            t = tokens[i]
            if t.type != T.t_uniq:
                i += 1
                continue

            text = t.text
            try:
                match = uniquifier.uniq2repl[text]
            except KeyError:
                t.type == T.t_text
                i += 1
                continue

            vlist = match["vlist"]
            if vlist:
                vlist = util.parseParams(vlist)
            else:
                vlist = None

            inner = match["inner"]
            name = match["tagname"]

            try:
                m = getattr(self, "create_" + str(name))
            except AttributeError:
                m = self._create_generic

            tokens[i] = m(name, vlist, inner or u"", xopts)
            if tokens[i] is None:
                del tokens[i]
            else:
                i += 1
コード例 #6
0
ファイル: core.py プロジェクト: uncletall/mwlib
    def __init__(self, tokens, xopts):
        self.tagextensions = tagext.default_registry

        uniquifier = xopts.uniquifier
        if uniquifier is None:
            return

        i = 0
        while i < len(tokens):
            t = tokens[i]
            if t.type != T.t_uniq:
                i += 1
                continue

            text = t.text
            try:
                match = uniquifier.uniq2repl[text]
            except KeyError:
                t.type == T.t_text
                i += 1
                continue

            vlist = match["vlist"]
            if vlist:
                vlist = util.parseParams(vlist)
            else:
                vlist = None

            inner = match["inner"]
            name = match["tagname"]

            try:
                m = getattr(self, "create_" + str(name))
            except AttributeError:
                m = self._create_generic

            tokens[i] = m(name, vlist, inner or u"", xopts)
            if tokens[i] is None:
                del tokens[i]
            else:
                i += 1
コード例 #7
0
    def find_caption(self, table):
        children = table.children
        start = None
        i = 0
        while i < len(children):
            t = children[i]
            if t.type == T.t_tablecaption:
                start = i
                i += 1
                break

            if t.text is None or t.text.strip():
                return
            i += 1

        modifier = None

        while i < len(children):
            t = children[i]
            if t.tagname not in ("ref", ) and (t.text is None
                                               or t.text.startswith("\n")):
                if modifier:
                    mod = T.join_as_text(children[start:modifier])
                    vlist = util.parseParams(mod)
                    sub = children[modifier + 1:i]
                else:
                    sub = children[start + 1:i]
                    vlist = {}

                caption = T(type=T.t_complex_caption,
                            children=sub,
                            vlist=vlist)
                children[start:i] = [caption]
                return
            elif t.text == "|" and modifier is None:
                modifier = i
            elif t.type == T.t_2box_open and modifier is None:
                modifier = 0

            i += 1
コード例 #8
0
ファイル: parse_table.py プロジェクト: pediapress/mwlib
    def find_caption(self, table):
        children = table.children
        start = None
        i = 0
        while i < len(children):
            t = children[i]
            if t.type == T.t_tablecaption:
                start = i
                i += 1
                break

            if t.text is None or t.text.strip():
                return
            i += 1

        modifier = None

        while i < len(children):
            t = children[i]
            if t.tagname not in ("ref",) and (t.text is None or t.text.startswith("\n")):
                if modifier:
                    mod = T.join_as_text(children[start:modifier])
                    vlist = util.parseParams(mod)
                    sub = children[modifier + 1:i]
                else:
                    sub = children[start + 1:i]
                    vlist = {}

                caption = T(type=T.t_complex_caption, children=sub, vlist=vlist)
                children[start:i] = [caption]
                return
            elif t.text == "|" and modifier is None:
                modifier = i
            elif t.type == T.t_2box_open and modifier is None:
                modifier = 0

            i += 1
コード例 #9
0
 def compute_mod():
     mod = T.join_as_text(children[:i])
     #print "MODIFIER:", repr(mod)
     table.vlist = util.parseParams(mod)
     del children[:i]
コード例 #10
0
def test_display_none():
    r = parseParams("class=geo style=display:none")
    assert r == {'class': 'geo', 'style': {'display': 'none'}}
コード例 #11
0
def test_bgcolor_hashmark_no_doublequote():
    """http://code.pediapress.com/wiki/ticket/654"""
    r = parseParams("bgcolor=#ffffff")
    assert r == dict(bgcolor="#ffffff")
コード例 #12
0
ファイル: test_parser.py プロジェクト: aarddict/mwlib
    def check(s, expected):
        res= util.parseParams(s)
        print repr(s), "-->", res, "expected:", expected

        assert res==expected, "bad result"
コード例 #13
0
ファイル: test_parser.py プロジェクト: vprusa/mwlib
    def check(s, expected):
        res = util.parseParams(s)
        print repr(s), "-->", res, "expected:", expected

        assert res == expected, "bad result"