changeset 2730:a907a61c33b3

* The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better (bug) compatibility. * Wiki parser fixes. * Reverted split_wiki/resolve_wiki to 1.5.8 code. The 1.6/1.7 code supported pagename quoting and this is not used any more. Also we need the (broken) 1.5.8 code to have the converter behave as 1.5.8 would do. Added deprecation notes for this old code. * Added new split_interwiki/resolve_interwiki code as replacement. * HTML formatter's attachment_link method got a new kw arg 'text_format' so we can call it with non-text link descriptions (e.g. images), too. * misc. fixes/cleanups
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 19 Aug 2007 19:28:35 +0200
parents 012d5ec31f92
children a62313ef3473
files MoinMoin/_tests/test_wikiutil.py MoinMoin/formatter/text_html.py MoinMoin/parser/text_moin_wiki.py MoinMoin/script/migration/_conv160.py MoinMoin/script/migration/_conv160_wiki.py MoinMoin/script/migration/_tests/test_conv160_wiki.py MoinMoin/wikiutil.py
diffstat 7 files changed, 316 insertions(+), 281 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/test_wikiutil.py	Mon Aug 13 04:06:53 2007 +0200
+++ b/MoinMoin/_tests/test_wikiutil.py	Sun Aug 19 19:28:35 2007 +0200
@@ -68,20 +68,14 @@
 
 class TestInterWiki:
     def testSplitWiki(self):
-        tests = [('SomePage', ('Self', 'SomePage', '')),
-                 ('OtherWiki:OtherPage', ('OtherWiki', 'OtherPage', '')),
-                 ('MoinMoin:"Page with blanks" link title', ("MoinMoin", "Page with blanks", "link title")),
-                 ('MoinMoin:"Page with blanks"link title', ("MoinMoin", "Page with blanks", "link title")),
-                 ('MoinMoin:"Page with blanks"', ("MoinMoin", "Page with blanks", "")),
-                 ('MoinMoin:"Page with ""quote""" link title', ("MoinMoin", 'Page with "quote"', "link title")),
-                 ('MoinMoin:"Page with """"double-quote"""link title', ("MoinMoin", 'Page with ""double-quote"', "link title")),
-                 ('MoinMoin:"""starts with quote"link title', ("MoinMoin", '"starts with quote', "link title")),
-                 ('MoinMoin:"ends with quote"""link title', ("MoinMoin", 'ends with quote"', "link title")),
-                 ('MoinMoin:"""page with quotes around"""link title', ("MoinMoin", '"page with quotes around"', "link title")),
-                 ('attachment:"filename with blanks.txt" other title', ("attachment", "filename with blanks.txt", "other title")),
+        tests = [('SomePage', ('Self', 'SomePage')),
+                 ('OtherWiki:OtherPage', ('OtherWiki', 'OtherPage')),
+                 (':OtherPage', ('', 'OtherPage')),
+                 # broken ('/OtherPage', ('Self', '/OtherPage')),
+                 # wrong interpretation ('MainPage/OtherPage', ('Self', 'MainPage/OtherPage')),
                 ]
-        for markup, (wikiname, pagename, linktext) in tests:
-            assert wikiutil.split_wiki(markup) == (wikiname, pagename, linktext)
+        for markup, (wikiname, pagename) in tests:
+            assert wikiutil.split_wiki(markup) == (wikiname, pagename)
 
     def testJoinWiki(self):
         tests = [(('http://example.org/', u'SomePage'), 'http://example.org/SomePage'),
--- a/MoinMoin/formatter/text_html.py	Mon Aug 13 04:06:53 2007 +0200
+++ b/MoinMoin/formatter/text_html.py	Sun Aug 19 19:28:35 2007 +0200
@@ -602,6 +602,15 @@
     # Attachments ######################################################
 
     def attachment_link(self, url, text, **kw):
+        """ Link to an attachment.
+
+            @param url: PageName/attachedfile.txt or attachedfile.txt
+            @param text: usually the text to show for the link,
+                         but can also be an <img> tag (see text_format kw arg)
+            @keyword text_format: default True (run text through text formatter),
+                                  use False if you give an <img> tag to text param.
+            @return: markup for the attachment link
+        """
         _ = self.request.getText
         pagename, filename = AttachFile.absoluteName(url, self.page.page_name)
         #self.request.log("attachment_link: url %s pagename %s filename %s" % (url, pagename, filename))
@@ -618,8 +627,11 @@
         # no 'alt' - alt is only for images
         if not 'title' in kw:
             kw['title'] = _('Attached file: %(url)s') % {'url': self.text(url)}
+        text_format = kw.get('text_format', True) # can be False for e.g. <img ...>
+        if text_format:
+            text = self.text(text) # run through text formatter
         return (self.url(1, target, css='attachment', title=kw['title']) +
-                self.text(text) +
+                text +
                 self.url(0))
 
     def attachment_image(self, url, **kw):
--- a/MoinMoin/parser/text_moin_wiki.py	Mon Aug 13 04:06:53 2007 +0200
+++ b/MoinMoin/parser/text_moin_wiki.py	Sun Aug 19 19:28:35 2007 +0200
@@ -522,7 +522,8 @@
 
         wikitag_bad = wikiutil.resolve_interwiki(self.request, wiki, page)[3]
         if wikitag_bad:
-            return self.formatter.text(word)
+            text = groups.get('interwiki')
+            return self.formatter.text(text)
         else:
             return (self.formatter.interwikilink(1, wiki, page) +
                     self.formatter.text(page) +
@@ -646,9 +647,10 @@
         """Handle [[target|text]] links."""
         target = groups.get('link_target', '')
         args = (groups.get('link_args', '') or '').strip()
-        m = self.link_target_re.match(target)
+        mt = self.link_target_re.match(target)
         ma = self.link_desc_re.match(args)
         desc = None
+        desc_format = True # run desc through text formatter?
         if ma:
             if ma.group('simple_text'):
                 desc = ma.group('simple_text')
@@ -661,9 +663,10 @@
                     groupdict['transclude_args'] = target
                 desc = ma.group('transclude')
                 desc = self._transclude_repl(desc, groupdict)
-        if m:
-            if m.group('page_name'):
-                page_name = m.group('page_name')
+                desc_format = False
+        if mt:
+            if mt.group('page_name'):
+                page_name = mt.group('page_name')
                 # handle relative links
                 if page_name.startswith(self.CHILD_PREFIX):
                     page_name = self.formatter.page.page_name + '/' + page_name[self.CHILD_PREFIX_LEN:] # XXX use func
@@ -680,18 +683,18 @@
                         desc +
                         self.formatter.pagelink(0, page_name))
 
-            elif m.group('extern_addr'):
-                scheme = m.group('extern_scheme')
-                target = m.group('extern_addr')
+            elif mt.group('extern_addr'):
+                scheme = mt.group('extern_scheme')
+                target = mt.group('extern_addr')
                 if not desc:
                     desc = self.formatter.text(target)
                 return (self.formatter.url(1, target, css=scheme) +
                         desc +
                         self.formatter.url(0))
 
-            elif m.group('inter_wiki'):
-                wiki_name = m.group('inter_wiki')
-                page_name = m.group('inter_page')
+            elif mt.group('inter_wiki'):
+                wiki_name = mt.group('inter_wiki')
+                page_name = mt.group('inter_page')
                 wikitag_bad = wikiutil.resolve_interwiki(self.request, wiki_name, page_name)[3]
                 if not desc:
                     desc = self.formatter.text(page_name)
@@ -699,13 +702,16 @@
                         desc +
                         self.formatter.interwikilink(0, wiki_name, page_name))
 
-            elif m.group('attach_scheme'):
-                scheme = m.group('attach_scheme')
-                url = wikiutil.url_unquote(m.group('attach_addr'), want_unicode=True)
+            elif mt.group('attach_scheme'):
+                scheme = mt.group('attach_scheme')
+                url = wikiutil.url_unquote(mt.group('attach_addr'), want_unicode=True)
                 if not desc:
                     desc = self.formatter.text(url)
                 if scheme == 'attachment':
-                    return self.formatter.attachment_link(url, desc, title=desc)
+                    if desc_format:
+                        return self.formatter.attachment_link(url, text=desc, title=desc, text_format=desc_format)
+                    else:
+                        return self.formatter.attachment_link(url, text=desc, text_format=desc_format)
                 elif scheme == 'drawing':
                     return self.formatter.attachment_drawing(url, desc, title=desc, alt=desc)
             else:
--- a/MoinMoin/script/migration/_conv160.py	Mon Aug 13 04:06:53 2007 +0200
+++ b/MoinMoin/script/migration/_conv160.py	Sun Aug 19 19:28:35 2007 +0200
@@ -1,6 +1,6 @@
 # -*- coding: iso-8859-1 -*-
 """
-    MoinMoin - migration from base rev 105xxyy
+    MoinMoin - migration from 1.5.8 to 1.6.0 (creole link style)
 
     What it should do when it is ready:
 
--- a/MoinMoin/script/migration/_conv160_wiki.py	Mon Aug 13 04:06:53 2007 +0200
+++ b/MoinMoin/script/migration/_conv160_wiki.py	Sun Aug 19 19:28:35 2007 +0200
@@ -1,6 +1,7 @@
 # -*- coding: iso-8859-1 -*-
 """
-    MoinMoin - convert content in wiki markup
+    MoinMoin - convert content in 1.5.8 wiki markup to 1.6.0 style
+               by using a modified 1.5.8 parser as translator.
 
     Assuming we have this "renames" map:
     -------------------------------------------------------
@@ -24,21 +25,77 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-import re, codecs
+import re
+
 from MoinMoin import i18n
-i18n.wikiLanguages = lambda: []
-from MoinMoin import config, wikiutil
-from early16_text_moin_wiki import Parser
+i18n.wikiLanguages = lambda: {}
+
+from MoinMoin import config, wikiutil, macro
 from MoinMoin.action import AttachFile
+from MoinMoin.Page import Page
+
+from text_moin158_wiki import Parser
+
+def convert_wiki(request, pagename, intext, renames):
+    """ Convert content written in wiki markup """
+    noeol = False
+    if not intext.endswith('\r\n'):
+        intext += '\r\n'
+        noeol = True
+    c = Converter(request, pagename, intext, renames)
+    result = request.redirectedOutput(c.convert, request)
+    if noeol and result.endswith('\r\n'):
+        result = result[:-2]
+    return result
+
 
 class Converter(Parser):
-    def __init__(self, pagename, raw, renames):
-        self.request = None
+    def __init__(self, request, pagename, raw, renames):
         self.pagename = pagename
         self.raw = raw
         self.renames = renames
-        self.in_pre = False
+        self.request = request
         self._ = None
+        self.in_pre = 0
+
+        self.formatting_rules = self.formatting_rules % {'macronames': u'|'.join(macro.getNames(self.request.cfg))}
+
+    # no change
+
+    def return_word(self, word):
+        return word
+    _emph_repl = return_word
+    _emph_ibb_repl = return_word
+    _emph_ibi_repl = return_word
+    _emph_ib_or_bi_repl = return_word
+    _u_repl = return_word
+    _strike_repl = return_word
+    _sup_repl = return_word
+    _sub_repl = return_word
+    _small_repl = return_word
+    _big_repl = return_word
+    _tt_repl = return_word
+    _tt_bt_repl = return_word
+    _remark_repl = return_word
+    _table_repl = return_word
+    _tableZ_repl = return_word
+    _rule_repl = return_word
+    _smiley_repl = return_word
+    _smileyA_repl = return_word
+    _ent_repl = return_word
+    _ent_numeric_repl = return_word
+    _ent_symbolic_repl = return_word
+    _heading_repl = return_word
+    _email_repl = return_word
+    _notword_repl = return_word
+    _indent_repl = return_word
+    _li_none_repl = return_word
+    _li_repl = return_word
+    _ol_repl = return_word
+    _dl_repl = return_word
+    _comment_repl = return_word
+
+    # translate pagenames using pagename translation map
 
     def _replace(self, key):
         """ replace a item_name if it is in the renames dict
@@ -59,69 +116,6 @@
             pass # TODO we have to fix the (absolute) new_name to be a relative name (as it was before)
         return new_name
 
-    def return_word(self, word):
-        return word
-    _remark_repl = return_word
-    _table_repl = return_word
-    _tableZ_repl = return_word
-    _emph_repl = return_word
-    _emph_ibb_repl = return_word
-    _emph_ibi_repl = return_word
-    _emph_ib_or_bi_repl = return_word
-    _u_repl = return_word
-    _strike_repl = return_word
-    _sup_repl = return_word
-    _sub_repl = return_word
-    _small_repl = return_word
-    _big_repl = return_word
-    _tt_repl = return_word
-    _tt_bt_repl = return_word
-    _notword_repl = return_word
-    _rule_repl = return_word
-    _smiley_repl = return_word
-    _smileyA_repl = return_word
-    _ent_repl = return_word
-    _ent_numeric_repl = return_word
-    _ent_symbolic_repl = return_word
-    _heading_repl = return_word
-    _email_repl = return_word
-    _word_repl = return_word
-    _indent_repl = return_word
-    _li_none_repl = return_word
-    _li_repl = return_word
-    _ol_repl = return_word
-    _dl_repl = return_word
-    _comment_repl = return_word
-
-    # PRE SECTION HANDLING ---------------------------------------------------
-
-    def _pre_repl(self, word):
-        origw = word
-        word = word.strip()
-        if word == '{{{' and not self.in_pre:
-            self.in_pre = True
-            return origw
-        elif word == '}}}' and self.in_pre:
-            self.in_pre = False
-            return origw
-        return word
-
-    def _parser_repl(self, word):
-        origw = word
-        if word.startswith('{{{'):
-            word = word[3:]
-
-        s_word = word.strip()
-        self.in_pre = True
-        return origw
-
-    def _macro_repl(self, word):
-        stripped_old = word[2:-2]
-        decorated_new = "<<%s>>" % stripped_old
-        # XXX later check whether some to be renamed pagename is used as macro param
-        return decorated_new
-
-    # LINKS ------------------------------------------------------------------
     def _replace_target(self, target):
         target_and_anchor = target.split('#', 1)
         if len(target_and_anchor) > 1:
@@ -132,33 +126,30 @@
             target = self._replace(('PAGE', target))
             return target
 
-    def interwiki(self, target_and_text, **kw):
-        scheme, rest = target_and_text.split(':', 1)
-        wikiname, pagename, text = wikiutil.split_wiki(rest)
-        if wikiname in ('Self', self.request.cfg.interwikiname): # our wiki
-            pagename = self._replace(('PAGE', pagename))
-        #pagename = pagename.replace('_', ' ') # better not touch this
-        pagename = wikiutil.url_unquote(pagename)
-        return scheme, wikiname, pagename, text
+    # markup conversion
 
-    def attachment(self, target_and_text, **kw):
-        """ This gets called on attachment URLs """
-        _ = self._
-        scheme, fname, text = wikiutil.split_wiki(target_and_text)
-        pagename, fname = AttachFile.absoluteName(fname, self.pagename)
-        from_this_page = pagename == self.pagename
-        fname = self._replace(('FILE', pagename, fname))
-        if '%20' in fname:
-            fname = fname.replace('%20', ' ')
-        fname = self._replace(('FILE', pagename, fname))
-        pagename = self._replace(('PAGE', pagename))
-        if from_this_page:
-            name = fname
+    def _macro_repl(self, word):
+        # we use [[...]] for links now, macros will be <<...>>
+        stripped_old = word[2:-2]
+        decorated_new = "<<%s>>" % stripped_old
+        # XXX later check whether some to be renamed pagename is used as macro param
+        return decorated_new
+
+    def _word_repl(self, word, text=None):
+        """Handle WikiNames."""
+        if not text:
+            return word
+        else: # internal use:
+            return '[[%s|%s]]' % (word, text)
+
+    def _wikiname_bracket_repl(self, word):
+        """Handle special-char wikinames."""
+        pagename = word[2:-2]
+        if pagename:
+            pagename = self._replace(('PAGE', pagename))
+            return '[[%s]]' % pagename
         else:
-            name = "%s/%s" % (pagename, fname)
-        if text:
-            text = '|' + text
-        return "%s:%s%s" % (scheme, name, text)
+            return word
 
     def _interwiki_repl(self, word):
         """Handle InterWiki links."""
@@ -166,68 +157,119 @@
         if wikitag_bad:
             return word
         else:
-            scheme, wikiname, pagename, text = self.interwiki("wiki:" + word)
-            iswiki = wikiutil.isStrictWikiname(pagename)
-            if wikiname == 'Self':
-                if iswiki:
+            wikiname, pagename = word.split(':', 1)
+            pagename = wikiutil.url_unquote(pagename) # maybe someone has used %20 for blanks in pagename
+            camelcase = wikiutil.isStrictWikiname(pagename)
+            if wikiname in ('Self', self.request.cfg.interwikiname):
+                pagename = self._replace(('PAGE', pagename))
+                if camelcase:
                     return '%s' % pagename # optimize special case
                 else:
                     return '[[%s]]' % pagename # optimize special case
             else:
-                if ' ' not in pagename: # XXX we could get a ' '  by urlunquoting
-                    return "%s:%s" % (wikiname, pagename)
+                if ' ' in pagename: # we could get a ' '  by urlunquoting
+                    return '[[%s:%s]]' % (wikiname, pagename)
                 else:
-                    return "[[%s:%s]]" % (wikiname, pagename)
+                    return '%s:%s' % (wikiname, pagename)
+
+    def interwiki(self, url_and_text):
+        if len(url_and_text) == 1:
+            url = url_and_text[0]
+            text = ''
+        else:
+            url, text = url_and_text
+            text = '|' + text
+
+        # keep track of whether this is a self-reference, so links
+        # are always shown even the page doesn't exist.
+        scheme, url = url.split(':', 1)
+        wikiname, pagename = wikiutil.split_wiki(url)
+        if (url.startswith(wikiutil.CHILD_PREFIX) or # fancy link to subpage [wiki:/SubPage text]
+            wikiname in ('Self', self.request.cfg.interwikiname, '') or # [wiki:Self:LocalPage text] or [:LocalPage:text]
+            Page(self.request, url).exists()): # fancy link to local page [wiki:LocalPage text]
+            pagename = wikiutil.url_unquote(pagename)
+            pagename = self._replace_target(pagename)
+            return '[[%s%s]]' % (pagename, text)
+
+        wikitag, wikiurl, wikitail, wikitag_bad = wikiutil.resolve_wiki(self.request, url)
+        wikitail = wikiutil.url_unquote(wikitail)
+
+        # link to self?
+        if wikitag is None:
+            if wikiutil.isPicture(wikitail):
+                return '{{%s%s}}' % (wikitail, text)
+            else:
+                return '[[%s%s]]' % (wikitail, text)
+        else:
+            if wikiutil.isPicture(wikitail):
+                return '{{%s:%s%s}}' % (wikitag, wikitail, text)
+            else:
+                return '[[%s:%s%s]]' % (wikitag, wikitail, text)
+
+    def attachment(self, url_and_text):
+        """ This gets called on attachment URLs. """
+        if len(url_and_text) == 1:
+            url = url_and_text[0]
+            text = ''
+        else:
+            url, text = url_and_text
+            text = '|' + text
+
+        scheme, fname = url.split(":", 1)
+        #scheme, fname, text = wikiutil.split_wiki(target_and_text)
+
+        pagename, fname = AttachFile.absoluteName(fname, self.pagename)
+        from_this_page = pagename == self.pagename
+        fname = self._replace(('FILE', pagename, fname))
+        fname = wikiutil.url_unquote(fname, want_unicode=True)
+        fname = self._replace(('FILE', pagename, fname))
+        pagename = self._replace(('PAGE', pagename))
+        if from_this_page:
+            name = fname
+        else:
+            name = "%s/%s" % (pagename, fname)
+
+        if scheme == 'drawing':
+            return "{{drawing:%s%s}}" % (name, text)
+
+        # check for image URL, and possibly return IMG tag
+        # (images are always inlined, just like for other URLs)
+        if wikiutil.isPicture(name):
+            if not text:
+                text = name.split('/')[-1]
+                text = ''.join(text.split('.')[:-1])
+                text = wikiutil.url_unquote(text) # maybe someone has used %20 for blanks
+                text = '|' + text
+            return "{{attachment:%s%s}}" % (name, text)
+
+        # inline the attachment
+        if scheme == 'inline':
+            return '{{attachment:%s%s}}' % (name, text)
+        else: # 'attachment'
+            return '[[attachment:%s%s]]' % (name, text)
 
     def _url_repl(self, word):
         """Handle literal URLs including inline images."""
         scheme = word.split(":", 1)[0]
 
-        if scheme == "wiki":
-            scheme, wikiname, pagename, text = self.interwiki(word)
-            # XXX remap pagename
-            # XXX check pagename if it contains a blank
-            if wikiname == 'Self':
-                return '[[%s]]' % pagename # optimize special case
-            else:
-                return "[[%s:%s]]" % (wikiname, pagename)
+        if scheme == 'wiki':
+            return self.interwiki([word])
+        if scheme in self.attachment_schemas:
+            return '%s' % self.attachment([word])
 
-        if scheme in self.attachment_schemas:
-            return "[[%s]]" % self.attachment(word)
-
-        if wikiutil.isPicture(word):
-            # Get image name http://here.com/dir/image.gif -> image
+        if wikiutil.isPicture(word): # magic will go away in 1.6!
             name = word.split('/')[-1]
             name = ''.join(name.split('.')[:-1])
-            return "{{%s}}" % word # we need transclusion syntax now!
+            name = wikiutil.url_unquote(name) # maybe someone has used %20 for blanks
+            return '{{%s|%s}}' % (word, name) # new markup for inline images
         else:
-            return word # word, scheme
-
-    def _wikiname_bracket_repl(self, text):
-        """Handle special-char wikinames with link text, like:
-           ["Jim O'Brian" Jim's home page] or ['Hello "world"!' a page with doublequotes]i
-        """
-        word = text[1:-1] # strip brackets
-        first_char = word[0]
-        if first_char in wikiutil.QUOTE_CHARS:
-            # split on closing quote
-            target, linktext = word[1:].split(first_char, 1)
-            target = self._replace_target(target)
-        else: # not quoted
-            # split on whitespace
-            target, linktext = word.split(None, 1)
-            target = self._replace_target(target)
-        linktext = linktext.strip()
-        if linktext:
-            linktext = '|' + linktext
-        return '[[%s%s]]' % (target, linktext)
-
+            return word
 
     def _url_bracket_repl(self, word):
         """Handle bracketed URLs."""
         word = word[1:-1] # strip brackets
 
-        # Local extended link? [:page name:link text]
+        # Local extended link?
         if word[0] == ':':
             words = word[1:].split(':', 1)
             link, text = (words + ['', ''])[:2]
@@ -238,37 +280,57 @@
                 text = '|' + text
             return '[[%s%s]]' % (link, text)
 
-        scheme_and_rest = word.split(":", 1)
-        if len(scheme_and_rest) == 2: # scheme given
-            scheme, rest = scheme_and_rest
-            if scheme == "wiki":
-                scheme, wikiname, pagename, text = self.interwiki(word, pretty_url=1)
-                if wikiname == 'Self':
-                    if text:
-                        text = '|' + text
-                    return '[[%s%s]]' % (pagename, text)
-                else:
-                    if text:
-                        text = '|' + text
-                    return "[[%s:%s%s]]" % (wikiname, pagename, text)
-            if scheme in self.attachment_schemas:
-                return '[[%s]]' % self.attachment(word, pretty_url=1)
+        # Traditional split on space
+        words = word.split(None, 1)
+        if words[0][0] == '#':
+            # anchor link
+            link, text = (words + ['', ''])[:2]
+            if link.strip() == text.strip():
+                text = ''
+            #link = self._replace_target(link)
+            if text:
+                text = '|' + text
+            return '[[%s%s]]' % (link, text)
 
-        words = word.split(None, 1)
-        if len(words) == 1:
-            link, text = words[0], ''
+        scheme = words[0].split(":", 1)[0]
+        if scheme == "wiki":
+            return self.interwiki(words)
+            #scheme, wikiname, pagename, text = self.interwiki(word)
+            #print "%r %r %r %r" % (scheme, wikiname, pagename, text)
+            #if wikiname in ('Self', self.request.cfg.interwikiname, ''):
+            #    if text:
+            #        text = '|' + text
+            #    return '[[%s%s]]' % (pagename, text)
+            #else:
+            #    if text:
+            #        text = '|' + text
+            #    return "[[%s:%s%s]]" % (wikiname, pagename, text)
+        if scheme in self.attachment_schemas:
+            return '%s' % self.attachment(words)
+
+        target, desc = (words + ['', ''])[:2]
+        if wikiutil.isPicture(desc) and re.match(self.url_rule, desc):
+            #return '[[%s|{{%s|%s}}]]' % (words[0], words[1], words[0])
+            return '[[%s|{{%s}}]]' % (target, desc)
         else:
-            link, text = words
-        if text:
-            text = '|' + text
-        return '[[%s%s]]' % (link, text)
+            if desc:
+                desc = '|' + desc
+            return '[[%s%s]]' % (target, desc)
 
-    # SCANNING ---------------------------------------------------------------
+    def _pre_repl(self, word):
+        w = word.strip()
+        if w == '{{{' and not self.in_pre:
+            self.in_pre = True
+        elif w == '}}}' and self.in_pre:
+            self.in_pre = False
+        return word
+
+    def _processor_repl(self, word):
+        self.in_pre = True
+        return word
+
     def scan(self, scan_re, line):
-        """ Scans one line
-
-        Append text before match, invoke replace() with match, and add text after match.
-        """
+        """ Scans one line - append text before match, invoke replace() with match, and add text after match.  """
         result = []
         lastpos = 0
 
@@ -284,6 +346,7 @@
         result.append(line[lastpos:])
         return u''.join(result)
 
+
     def replace(self, match):
         """ Replace match using type name """
         result = []
@@ -291,6 +354,7 @@
             if hit is not None and not _type in ["hmarker", ]:
                 # Get replace method and replace hit
                 replace = getattr(self, '_' + _type + '_repl')
+                # print _type, hit
                 result.append(replace(hit))
                 return ''.join(result)
         else:
@@ -311,21 +375,21 @@
         self.request = request
         # prepare regex patterns
         rules = self.formatting_rules.replace('\n', '|')
-        if 1: # self.cfg.bang_meta:
+        if self.request.cfg.bang_meta:
             rules = ur'(?P<notword>!%(word_rule)s)|%(rules)s' % {
                 'word_rule': self.word_rule,
                 'rules': rules,
             }
-        pre_rules = self.pre_formatting_rules.replace('\n', '|')
+        #pre_rules = self.pre_formatting_rules.replace('\n', '|')
+        #pre_scan_re = re.compile(pre_rules, re.UNICODE)
         scan_re = re.compile(rules, re.UNICODE)
-        pre_scan_re = re.compile(pre_rules, re.UNICODE)
         eol_re = re.compile(r'\r?\n', re.UNICODE)
 
         rawtext = self.raw
 
         # remove last item because it's guaranteed to be empty
         self.lines = eol_re.split(rawtext)[:-1]
-        self.in_processing_instructions = 1
+        self.in_processing_instructions = True
 
         # Main loop
         for line in self.lines:
@@ -339,38 +403,14 @@
                         found = True
                         break
                 if not found:
-                    self.in_processing_instructions = 0
+                    self.in_processing_instructions = False
                 else:
                     continue # do not parse this line
-            if self.in_pre:
-                # still looking for processing instructions
-                if self.in_pre == 'search_parser':
-                    if line.strip().startswith("#!"):
-                        self.in_pre = True
-                        self.request.write(line + '\r\n')
-                        continue
-                    else:
-                        self.in_pre = True
+            if not line.strip():
+                self.request.write(line + '\r\n')
             else:
-                # Paragraph break on empty lines
-                if not line.strip():
-                    self.request.write(line + '\r\n')
-                    continue
+                # Scan line, format and write
+                scanning_re = self.in_pre and pre_scan_re or scan_re
+                formatted_line = self.scan(scanning_re, line)
+                self.request.write(formatted_line + '\r\n')
 
-            # Scan line, format and write
-            scanning_re = self.in_pre and pre_scan_re or scan_re
-            formatted_line = self.scan(scanning_re, line)
-            self.request.write(formatted_line + '\r\n')
-
-def convert_wiki(request, pagename, intext, renames):
-    """ Convert content written in wiki markup """
-    noeol = False
-    if not intext.endswith('\r\n'):
-        intext += '\r\n'
-        noeol = True
-    p = Converter(pagename, intext, renames)
-    res = request.redirectedOutput(p.convert, request)
-    if noeol:
-        res = res[:-2]
-    return res
-
--- a/MoinMoin/script/migration/_tests/test_conv160_wiki.py	Mon Aug 13 04:06:53 2007 +0200
+++ b/MoinMoin/script/migration/_tests/test_conv160_wiki.py	Sun Aug 19 19:28:35 2007 +0200
@@ -38,17 +38,17 @@
 
         tests = [
             # FAILING tests:
-            #('[wiki:/OtherPage]', rename_some_page, '[wiki:/OtherPage]'),
+            #('[wiki:/OtherPage]', rename_some_page, '[[/OtherPage]]'),
             #('[wiki:/OtherPage other page]', rename_some_page, '[wiki:/OtherPage other page]'),
-            #('[attachment:My%20Attachment.jpg:it works]', {}, '[attachment:"My Attachment.jpg" it works]'),
+            #('[attachment:My%20Attachment.jpg:it works]', {}, '[[attachment:My Attachment.jpg|it works]]'),
             #('[wiki:LinuxWiki: LinuxWiki.de]', {}, '[wiki:LinuxWiki: LinuxWiki.de]'),
             #('[:MeatBall:CleanLinking meatball-wiki: clean linking]', {}, '[:MeatBall:CleanLinking meatball-wiki: clean linking]'),
 
             # ambiguity!!! can be resolved with some interwiki map lookup
-            # and transformed to wiki:SeaPig:BrianDorsey if SeaPig is in
-            # interwiki map, but no page SeaPig exists.
+            # and transformed to wiki:MoinMoin:FrontPage if MoinMoin is in
+            # interwiki map, but no page MoinMoin exists.
             #('[wiki:MacroMarket/EmbedObject EO]', {}, '["MacroMarket/EmbedObject" EO]'),
-            ('[wiki:SeaPig/BrianDorsey]', {}, '[[SeaPig:BrianDorsey]]'),
+            ('[wiki:MoinMoin/FrontPage]', {}, '[[MoinMoin:FrontPage]]'),
 
             # "nothing changed" checks (except markup)
             ('', {}, ''),
@@ -64,9 +64,9 @@
             ('http://some_server/some_page', rename_some_page, 'http://some_server/some_page'), # external link
             ('[http://some_server/some_page]', rename_some_page, '[[http://some_server/some_page]]'), # external link
             ('[#some_page]', rename_some_page, '[[#some_page]]'), # link to anchor that has same name
-            ('[attachment:some_page.png]', rename_some_page, '[[attachment:some_page.png]]'), # att, not page
-            ('[attachment:some_page.png test picture]', rename_some_page, '[[attachment:some_page.png|test picture]]'), # att, not page
-            ('[attachment:some_page.txt attachment:some_page.png]', rename_some_page, '[[attachment:some_page.txt|attachment:some_page.png]]'),
+            ('[attachment:some_page.png]', rename_some_page, '{{attachment:some_page.png|some_page}}'), # att, not page
+            ('[attachment:some_page.png test picture]', rename_some_page, '{{attachment:some_page.png|test picture}}'), # att, not page
+            #('[attachment:some_page.txt attachment:some_page.png]', rename_some_page, '[[attachment:some_page.txt|{{attachment:some_page.png}}]]'),
 
             # page rename changes result
             ('["some_page"]', rename_some_page, '[[some page]]'),
@@ -76,7 +76,7 @@
             ('Self:some_page', rename_some_page, '[[some page]]'),
             ('wiki:Self:some_page', rename_some_page, '[[some page]]'),
             ('[wiki:Self:some_page some text]', rename_some_page, '[[some page|some text]]'),
-            # FFF ('wiki:Self:some_page#some_anchor', rename_some_page, '[[some page#some_anchor]]'),
+            ('wiki:Self:some_page#some_anchor', rename_some_page, '[[some page#some_anchor]]'),
 
             # other markup changes we do
             ('[:other page]', {}, '[[other page]]'),
@@ -98,6 +98,16 @@
             ('attachment:keep%20blank', rename_some_file, '[[attachment:keep blank]]'), # no rename
             ('attachment:TestPage/keep%20blank', rename_some_file, '[[attachment:keep blank]]'), # remove superfluous pagename
             ('attachment:OtherPage/keep%20blank', rename_some_file, '[[attachment:OtherPage/keep blank]]'),
+
+            # embed images
+            ('http://server/image.png', {}, '{{http://server/image.png|image}}'),
+            ('attachment:image.gif', {}, '{{attachment:image.gif|image}}'),
+            ('inline:image.jpg', {}, '{{attachment:image.jpg|image}}'), # inline is now implied by {{...}}
+            ('drawing:image', {}, '{{drawing:image}}'),
+
+            # macros
+            ('[[BR]]', {}, '<<BR>>'),
+
         ]
         for data, renames, expected in tests:
             assert convert_wiki(request, pagename, data, renames) == expected
--- a/MoinMoin/wikiutil.py	Mon Aug 13 04:06:53 2007 +0200
+++ b/MoinMoin/wikiutil.py	Sun Aug 19 19:28:35 2007 +0200
@@ -578,56 +578,25 @@
     return _interwiki_list
 
 def split_wiki(wikiurl):
-    """ Split a wiki url, e.g:
-
-    'MoinMoin:FrontPage' -> "MoinMoin", "FrontPage", ""
-    'FrontPage' -> "Self", "FrontPage", ""
-    'MoinMoin:"Page with blanks" link title' -> "MoinMoin", "Page with blanks", "link title"
-
-    can also be used for:
-
-    'attachment:"filename with blanks.txt" other title' -> "attachment", "filename with blanks.txt", "other title"
+    """
+    Split a wiki url.
 
     *** DEPRECATED FUNCTION FOR OLD 1.5 SYNTAX - ONLY STILL HERE FOR THE 1.5 -> 1.6 MIGRATION ***
     Use split_interwiki(), see below.
 
     @param wikiurl: the url to split
     @rtype: tuple
-    @return: (wikiname, pagename, linktext)
+    @return: (tag, tail)
     """
+    # !!! use a regex here!
     try:
-        wikiname, rest = wikiurl.split(":", 1) # e.g. MoinMoin:FrontPage
+        wikitag, tail = wikiurl.split(":", 1)
     except ValueError:
         try:
-            wikiname, rest = wikiurl.split("/", 1) # for what is this used?
+            wikitag, tail = wikiurl.split("/", 1)
         except ValueError:
-            wikiname, rest = 'Self', wikiurl
-    if rest:
-        if rest[0] == '"': # quoted pagename
-            idx = 1
-            max = len(rest)
-            while idx < max:
-                if idx + 1 < max:
-                    next = rest[idx + 1]
-                else:
-                    next = None
-                if next == rest[idx] == '"':
-                    idx += 2
-                    continue
-                if next != '"' and rest[idx] == '"':
-                    break
-                idx += 1
-            pagename_linktext = rest[1:idx].replace('""', '"'), rest[idx+1:]
-        else: # not quoted, split on whitespace
-            pagename_linktext = rest.split(None, 1)
-    else:
-        pagename_linktext = "", ""
-    if len(pagename_linktext) == 1:
-        pagename, linktext = pagename_linktext[0], ""
-    else:
-        pagename, linktext = pagename_linktext
-    linktext = linktext.strip()
-    return wikiname, pagename, linktext
+            wikitag, tail = 'Self', wikiurl
+    return wikitag, tail
 
 def split_interwiki(wikiurl):
     """ Split a interwiki name, into wikiname and pagename, e.g:
@@ -652,7 +621,8 @@
     return wikiname, pagename
 
 def resolve_wiki(request, wikiurl):
-    """ Resolve an interwiki link.
+    """
+    Resolve an interwiki link.
 
     *** DEPRECATED FUNCTION FOR OLD 1.5 SYNTAX - ONLY STILL HERE FOR THE 1.5 -> 1.6 MIGRATION ***
     Use resolve_interwiki(), see below.
@@ -663,7 +633,10 @@
     @return: (wikitag, wikiurl, wikitail, err)
     """
     _interwiki_list = load_wikimap(request)
-    wikiname, pagename, linktext = split_wiki(wikiurl)
+    # split wiki url
+    wikiname, pagename = split_wiki(wikiurl)
+
+    # return resolved url
     if wikiname in _interwiki_list:
         return (wikiname, _interwiki_list[wikiname], pagename, False)
     else: