def parse_txt(txt, xopts=None, **kwargs): if xopts is None: xopts = XBunch(**kwargs) else: xopts.__dict__.update(**kwargs) if xopts.expander is None: from mwlib.expander import Expander, DictDB xopts.expander = Expander("", "pagename", wikidb=DictDB()) if xopts.nshandler is None: xopts.nshandler = nshandling.get_nshandler_for_lang(xopts.lang or 'en') xopts.imagemod = util.ImageMod(xopts.magicwords) uniquifier = xopts.uniquifier if uniquifier is None: uniquifier = uniq.Uniquifier() txt = uniquifier.replace_tags(txt) xopts.uniquifier = uniquifier tokens = tokenize(txt, uniquifier=uniquifier) td2 = tagparser() a = td2.add a("code", 10) a("span", 20) a("li", 25, blocknode=True, nested=False) a("dl", 28, blocknode=True) a("dt", 26, blocknode=True, nested=False) a("dd", 26, blocknode=True, nested=True) td1 = tagparser() a = td1.add a("blockquote", 5) a("references", 15) a("p", 30, blocknode=True, nested=False) a("ul", 35, blocknode=True) a("ol", 40, blocknode=True) a("center", 45, blocknode=True) td_parse_h = tagparser() for i in range(1, 7): td_parse_h.add("h%s" % i, i) parsers = [ fixlitags, mark_style_tags, parse_singlequote, parse_preformatted, td2, parse_paragraphs, td1, parse_lines, parse_div, parse_links, parse_urls, parse_inputbox, td_parse_h, parse_sections, remove_table_garbage, fix_tables, parse_tables, parse_uniq, fix_named_url_double_brackets, fix_break_between_pre ] combined_parser(parsers)(tokens, xopts) return tokens
def test_self_closing(): u = uniq.Uniquifier() s = u.replace_tags(""" <ref /> ---- <ref> </ref> """) assert s.count("UNIQ") == 2
def test_comment(): u = uniq.Uniquifier() def repl(txt, expected): res = u.replace_tags(txt) print repr(txt), "->", repr(res) assert res == expected yield repl, "foo<!-- bla -->bar", "foobar" yield repl, "foo\n<!-- bla -->\nbar", "foo\nbar" yield repl, "foo\n<!-- bla -->bar", "foo\nbar" yield repl, "foo<!-- bla -->\nbar", "foo\nbar"
def test_space_in_closing_tag(): u = uniq.Uniquifier() s = u.replace_tags("foo<ref>bar</ref >baz") assert "UNIQ" in s, "ref tag not recognized"
def test_empty_nowiki(): u = uniq.Uniquifier() s = u.replace_tags("abc<nowiki></nowiki>def") assert 'UNIQ' in s r = u.replace_uniq(s) assert r == "abcdef"