changeset 2771:1134a5cc12c2

gui converter fixes for new markup, fix/extend tests, remove unused code
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 26 Aug 2007 16:07:21 +0200
parents d1a1f10a0451
children 8ad0e79858ae
files MoinMoin/_tests/test_wikidicts.py MoinMoin/_tests/test_wikiutil.py MoinMoin/converter/text_html_text_moin_wiki.py MoinMoin/parser/text_moin_wiki.py MoinMoin/wikiutil.py
diffstat 5 files changed, 44 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/test_wikidicts.py	Sun Aug 26 14:14:54 2007 +0200
+++ b/MoinMoin/_tests/test_wikidicts.py	Sun Aug 26 16:07:21 2007 +0200
@@ -32,7 +32,7 @@
     def testExtendedLink(self):
         """ wikidicts: initFromText: extended link """
         text = """
- * ["extended link"]
+ * [[extended link]]
 """
         assert self.getMembers(text) == ['extended link']
 
--- a/MoinMoin/_tests/test_wikiutil.py	Sun Aug 26 14:14:54 2007 +0200
+++ b/MoinMoin/_tests/test_wikiutil.py	Sun Aug 26 16:07:21 2007 +0200
@@ -712,6 +712,21 @@
         encoded = wikiutil.anchor_name_from_text(text)
         assert expected == encoded
 
+class TestPageLinkMarkup:
+    def test_pagelinkmarkup(self):
+        tests = [
+            # pagename, expected markup
+            ('SomePage', 'SomePage'),
+            ('Somepage', '[[Somepage]]'),
+            ('somepage', '[[somepage]]'),
+            ('Some Page', '[[Some Page]]'),
+        ]
+        for pagename, expected in tests:
+            yield self._check, pagename, expected
+
+    def _check(self, pagename, expected):
+        assert expected == wikiutil.pagelinkmarkup(pagename)
+
 class TestRelativeTools:
     tests = [
         # test                      expected output
--- a/MoinMoin/converter/text_html_text_moin_wiki.py	Sun Aug 26 14:14:54 2007 +0200
+++ b/MoinMoin/converter/text_html_text_moin_wiki.py	Sun Aug 26 16:07:21 2007 +0200
@@ -1,7 +1,8 @@
 """
     MoinMoin - convert from html to wiki markup
 
-    @copyright: 2005-2006 Bastian Blank, Florian Festi, Thomas Waldmann, Reimar Bauer
+    @copyright: 2005-2006 Bastian Blank, Florian Festi, Reimar Bauer,
+                2005-2007 MoinMoin:ThomasWaldmann
     @license: GNU GPL, see COPYING for details.
 """
 
@@ -393,18 +394,6 @@
 ]>
 '''
 
-def pagename_from_url(url_frag):
-    """ url is a fragment of an URL we extract the pagename from by URL-unqouting
-        and possible adding quotes around the pagename if we detect blanks in it.
-    """
-    pagename = qpagename = wikiutil.url_unquote(url_frag)
-    if " " in pagename:
-        if not '"' in pagename:
-            qpagename = '"%s"' % pagename
-        elif not "'" in pagename:
-            qpagename = "'%s'" % pagename
-    return pagename, qpagename
-
 class visitor(object):
     def do(self, tree):
         self.visit_node_list(tree.childNodes)
@@ -1104,23 +1093,26 @@
                 wikitag, wikiurl, wikitail, err = wikiutil.resolve_interwiki(
                     self.request, title, "")
                 if not err and href.startswith(wikiurl):
-                    pagename, qpagename = pagename_from_url(href[len(wikiurl):].lstrip('/'))
-                    interwikiname = "%s:%s" % (wikitag, qpagename)
+                    pagename = wikiutil.url_unquote(href[len(wikiurl):].lstrip('/'))
+                    interwikiname = "%s:%s" % (wikitag, pagename)
                 else:
                     raise ConvertError("Invalid InterWiki link: '%s'" % href)
             elif class_ == "badinterwiki" and title:
                 if href == "/": # we used this as replacement for empty href
                     href = ""
-                pagename, qpagename = pagename_from_url(href)
-                interwikiname = "%s:%s" % (title, qpagename)
+                pagename = wikiutil.url_unquote(href)
+                interwikiname = "%s:%s" % (title, pagename)
             if interwikiname and pagename == text:
-                self.text.append("%s" % interwikiname)
+                if ' ' in interwikiname:
+                    self.text.append("[[%s]]" % interwikiname)
+                else:
+                    self.text.append("%s" % interwikiname)
                 return
             elif title == 'Self':
-                self.text.append('["%s" %s]' % (href, text))
+                self.text.append('[[%s|%s]]' % (href, text))
                 return
             elif interwikiname:
-                self.text.append("[wiki:%s %s]" % (interwikiname, text))
+                self.text.append("[[%s|%s]]" % (interwikiname, text))
                 return
 
             # fix links generated by a broken copy & paste of gecko based browsers
@@ -1131,11 +1123,11 @@
 
             # Attachments
             if title and title.startswith("attachment:"):
-                attname, qattname = pagename_from_url(title[len("attachment:"):])
-                if attname != text:
-                    self.text.append('[attachment:%s %s]' % (qattname, text))
+                attname = wikiutil.url_unquote(title[len("attachment:"):])
+                if attname != text or ' ' in attname:
+                    self.text.append('[[attachment:%s|%s]]' % (attname, text))
                 else:
-                    self.text.extend([self.white_space, 'attachment:%s' % qattname, self.white_space])
+                    self.text.extend([self.white_space, 'attachment:%s' % attname, self.white_space])
             # wiki link
             elif href.startswith(scriptname):
                 pagename = href[len(scriptname):]
@@ -1153,23 +1145,23 @@
                     self.text.append(wikiutil.pagelinkmarkup(text))
                 # labeled link
                 else:
-                    self.text.append('["%s" %s]' % (pagename, text))
+                    self.text.append('[[%s|%s]]' % (pagename, text))
             # mailto link
             elif href.startswith("mailto:"):
                 if href[len("mailto:"):] == text:
                     self.text.extend([self.white_space, text, self.white_space])
                 else:
-                    self.text.append("[%s %s]" % (href, text))
+                    self.text.append("[[%s|%s]]" % (href, text))
             # simple link
             elif href.replace(" ", "%20") == text:
                 self.text.append("%s" % text)
             # imagelink
             elif text == "" and wikiutil.isPicture(href):
-                self.text.append("[%s]" % href)
+                self.text.append("[[%s]]" % href)
             # labeled link
             else:
                 href = href.replace(" ", "%20")
-                self.text.append("[%s %s]" % (href, text))
+                self.text.append("[[%s|%s]]" % (href, text))
         elif id:
             pass # we dont support anchors yet
 
@@ -1198,7 +1190,7 @@
            ) or title is None or src.startswith('http:'):
             if height is None and width is None and target is None and not alt:
                 self.text.extend([self.white_space,
-                                  wikiutil.url_unquote(title),
+                                  "{{%s}}" % wikiutil.url_unquote(title),
                                   self.white_space])
             else:
                 # use ImageLink for resized images
@@ -1236,7 +1228,7 @@
             raise ConvertError("Unknown smiley icon '%s'" % filename)
         # Image URL
         elif src and src.startswith("http") and wikiutil.isPicture(src): # matches http: and https: !
-            self.text.extend([self.white_space, src, self.white_space])
+            self.text.extend([self.white_space, "{{%s}}" % src, self.white_space])
         else:
             raise ConvertError("Strange image src: '%s' alt == '%r'" % (src, alt))
 
--- a/MoinMoin/parser/text_moin_wiki.py	Sun Aug 26 14:14:54 2007 +0200
+++ b/MoinMoin/parser/text_moin_wiki.py	Sun Aug 26 16:07:21 2007 +0200
@@ -88,7 +88,11 @@
           (?:[%(u)s][%(l)s]+){2,}  # at least 2 upper>lower transitions make CamelCase
          )+  # we can have MainPage/SubPage/SubSubPage ...
         )
-        (?![%(u)s%(l)s/])  # require anything not upper/lower/slash following
+        (?:
+         (?![%(u)s%(l)s/])  # require anything not upper/lower/slash following
+         |
+         $  # ... or end of line
+        )
     ''' % {
         'u': config.chars_upper,
         'l': config.chars_lower,
--- a/MoinMoin/wikiutil.py	Sun Aug 26 14:14:54 2007 +0200
+++ b/MoinMoin/wikiutil.py	Sun Aug 26 16:07:21 2007 +0200
@@ -891,7 +891,7 @@
 def pagelinkmarkup(pagename):
     """ return markup that can be used as link to page <pagename> """
     from MoinMoin.parser.text_moin_wiki import Parser
-    if re.match(Parser.word_rule + "$", pagename):
+    if re.match(Parser.word_rule + "$", pagename, re.U|re.X):
         return pagename
     else:
         return u'[[%s]]' % pagename