Esempio n. 1
0
 def test_strip(self):
     result = self.parser.strip("[b]hello \n[i]world[/i][/b] -- []", strip_newlines=True)
     assert result == "hello world -- "
     # Not sure if I introduced a subtle bug here
     # assert result == 'hello world -- []'
     parser = AdfdParser(typogrify=False, hyphenate=False, tagOpener="<", tagCloser=">", dropUnrecognized=True)
     result = parser.strip('<div class="test"><b>hello</b> <i>world</i><img src="test.jpg" ' "/></div>")
     assert result == "hello world"
Esempio n. 2
0
    def test_linker(self):
        def _contextual_link(url, context):
            return '<a href="%s" target="_blank">%s</a>' % (url, context["substitution"])

        def _link(url):
            return _contextual_link(url, {"substitution": url})

        # Test noncontextual linker
        p = AdfdParser(typogrify=False, hyphenate=False, linker=_link)
        s = p._format_tokens(p.tokenize("hello www.apple.com world"), None)
        assert s == ('hello <a href="www.apple.com" ' 'target="_blank">www.apple.com</a> world')
        # Test contextual linker
        p = AdfdParser(typogrify=False, hyphenate=False, linker=_contextual_link, linkerTakesContext=True)
        s = p._format_tokens(p.tokenize("hello www.apple.com world"), None, substitution="oh hai")
        assert s == ('hello <a href="www.apple.com" ' 'target="_blank">oh hai</a> world')