Exemplo n.º 1
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')