Commits

Anonymous committed a74e93f

correct rendering of interwiki and mailto links

Comments (0)

Files changed (5)

MoinMoin/converter/_tests/test_moinwiki19_in.py

                 '<page><body><p><a xlink:href="wiki://Self/FrontPage">FrontPage</a></p></body></page>'),
             (u'http://moinmo.in/',
                 '<page><body><p><a xlink:href="http://moinmo.in/">http://moinmo.in/</a></p></body></page>'),
+            # email tests
+            (u'mailto:foo@bar.baz',
+                '<page><body><p><a xlink:href="mailto:foo@bar.baz">mailto:foo@bar.baz</a></p></body></page>'),
+            (u'foo@bar.baz',
+                '<page><body><p><a xlink:href="mailto:foo@bar.baz">foo@bar.baz</a></p></body></page>'),
+            (u'foo@bar', # 1.9 requires domain
+                '<page><body><p>foo@bar</p></body></page>'),
         ]
         for i in data:
             yield (self.do, ) + i

MoinMoin/converter/_tests/test_moinwiki_in.py

         ]
         for i in data:
             yield (self.do, ) + i
+    def test_interwiki(self):
+        data = [
+            (u'[[MoinMoin:RecentChanges]]',
+                '<page><body><p><a xlink:href="wiki://MoinMoin/RecentChanges">RecentChanges</a></p></body></page>'),
+            (u'[[MoinMoin:RecentChanges|changes]]',
+                '<page><body><p><a xlink:href="wiki://MoinMoin/RecentChanges">changes</a></p></body></page>'),
+            (u'[[MoinMoin:Foo/Bar.Baz]]',
+                '<page><body><p><a xlink:href="wiki://MoinMoin/Foo/Bar.Baz">Foo/Bar.Baz</a></p></body></page>'),
+            (u'[[MoinMoin:Blank In Page Name|blank in page name]]',
+                '<page><body><p><a xlink:href="wiki://MoinMoin/Blank%20In%20Page%20Name">blank in page name</a></p></body></page>'),
+            (u'[[InvalidWikiName:RecentChanges]]',
+                '<page><body><p><a xlink:href="wiki.local:InvalidWikiName:RecentChanges">InvalidWikiName:RecentChanges</a></p></body></page>'),
+        ]
+        for i in data:
+            yield (self.do, ) + i
+
+    def test_email(self):
+        data = [
+            (u'[[mailto:root]]',
+                '<page><body><p><a xlink:href="mailto:root">mailto:root</a></p></body></page>'),
+            (u'[[mailto:foo@bar.baz]]',
+                '<page><body><p><a xlink:href="mailto:foo@bar.baz">mailto:foo@bar.baz</a></p></body></page>'),
+            (u'[[mailto:foo@bar.baz|write me]]',
+                '<page><body><p><a xlink:href="mailto:foo@bar.baz">write me</a></p></body></page>'),
+            (u'[[mailto:foo.bar_baz@bar.baz]]', # . and _ are special characters commonly allowed by email systems
+                '<page><body><p><a xlink:href="mailto:foo.bar_baz@bar.baz">mailto:foo.bar_baz@bar.baz</a></p></body></page>'),
+        ]
+        for i in data:
+            yield (self.do, ) + i
 
     def serialize(self, elem, **options):
         from StringIO import StringIO

MoinMoin/converter/link.py

             # interwiki link
             wikitag, wikiurl, wikitail, err = resolve_interwiki(unicode(input.authority.host), unicode(input.path[1:]))
             if not err:
-                elem.set(html.class_, 'interwiki')
+                elem.set(html.class_, 'moin-interwiki')
                 if do is not None:
                     # this will only work for wikis with compatible URL design
                     # for other wikis, don't use do=... in your interwiki links

MoinMoin/converter/moinwiki19_in.py

                 )
             )
             (?P<url_target>
-                # TODO: config.url_schemas
-                (http|https|ftp|nntp|news|mailto|telnet|file|irc):
+                (%(url_schemas)s):
                 \S+?
             )
             (
                 )
             )
         )
-    """
+    """ % dict(url_schemas='|'.join(config.url_schemas))
 
     def inline_url_repl(self, stack, url, url_target):
         url = Iri(url_target)
 default_registry.register(ConverterFormat19.factory, Type('text/x.moin.wiki;format=1.9'), type_moin_document)
 default_registry.register(ConverterFormat19.factory, Type('x-moin/format;name=wiki;format=1.9'), type_moin_document)
 
+

MoinMoin/converter/moinwiki_in.py

 from MoinMoin import config
 from MoinMoin.util.iri import Iri
 from MoinMoin.util.tree import html, moin_page, xlink, xinclude
-
+from MoinMoin.util.interwiki import resolve_interwiki
 from ._args import Arguments
 from ._args_wiki import parse as parse_arguments
 from ._wiki_macro import ConverterMacro
             \s*
             (
                 (?P<link_url>
-                    [a-zA-Z0-9+.-]+
-                    ://
+                    (%(url_schemas)s):
                     [^|]+?
                 )
                 |
+                (
+                    (?P<link_interwiki_site>[A-Z][a-zA-Z]+)
+                    :
+                    (?P<link_interwiki_item>[^|]+) # accept any item name; will verify link_interwiki_site below
+                )
+                |
                 (?P<link_item> [^|]+? )
             )
             \s*
             )?
             \]\]
         )
-    """
+    """ % dict(url_schemas='|'.join(config.url_schemas))
 
     def inline_link_repl(self, stack, link, link_url=None, link_item=None,
-            link_text=None, link_args=None):
+            link_text=None, link_args=None,
+            link_interwiki_site=None, link_interwiki_item=None):
         """Handle all kinds of links."""
+        if link_interwiki_site:
+            err = resolve_interwiki(link_interwiki_site, link_interwiki_item)[3]
+            if not err:
+                link = Iri(scheme='wiki',
+                        authority=link_interwiki_site,
+                        path='/' + link_interwiki_item)
+                element = moin_page.a(attrib={xlink.href: link})
+                stack.push(element)
+                if link_text:
+                    self.parse_inline(link_text, stack, self.inlinedesc_re)
+                else:
+                    stack.top_append(link_interwiki_item)
+                stack.pop()
+                return
+            else:
+                # assume local language uses ":" inside of words, set link_item and continue
+                link_item = '%s:%s' % (link_interwiki_site, link_interwiki_item)
         if link_args:
             link_args = parse_arguments(link_args) # XXX needs different parsing
             query = url_encode(link_args.keyword, charset=config.charset, encode_keys=True)
         inline_macro,
         inline_nowiki,
         inline_emphstrong,
+        inline_object,
     )
     inlinedesc_re = re.compile('|'.join(inlinedesc), re.X | re.U)
 
 default_registry.register(Converter.factory, type_moin_wiki, type_moin_document)
 default_registry.register(Converter.factory, Type('x-moin/format;name=wiki'), type_moin_document)
 
+