changeset 1704:fe19c9ac4b82

text_gedit: Feature scalable images for gui added
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sat, 06 Jan 2007 15:27:29 +0100
parents 0803e5da055d
children 66b17318081d
files MoinMoin/converter/text_html_text_moin_wiki.py MoinMoin/formatter/text_gedit.py
diffstat 2 files changed, 84 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/converter/text_html_text_moin_wiki.py	Sat Jan 06 12:01:25 2007 +0100
+++ b/MoinMoin/converter/text_html_text_moin_wiki.py	Sat Jan 06 15:27:29 2007 +0100
@@ -1,7 +1,7 @@
 """
     MoinMoin - convert from html to wiki markup
 
-    @copyright: (c) Bastian Blank, Florian Festi, Thomas Waldmann
+    @copyright: (c) Bastian Blank, Florian Festi, Thomas Waldmann, Reimar Bauer
     @license: GNU GPL, see COPYING for details.
 """
 
@@ -1179,13 +1179,60 @@
         alt = None
         if node.attributes.has_key("alt"):
             alt = node.attributes.get("alt").nodeValue
+        width = None
+        if node.attributes.has_key("width"):
+            width = node.attributes.get("width").nodeValue
+        height = None
+        if node.attributes.has_key("height"):
+            height = node.attributes.get("height").nodeValue
+        target = None
+        if node.attributes.has_key("target"):
+            target = node.attributes.get("target").nodeValue
 
         # Attachment image
         if (title and title.startswith("attachment:") and
             wikiutil.isPicture(wikiutil.url_unquote(title[len("attachment:"):]))):
-            self.text.extend([self.white_space,
-                              wikiutil.url_unquote(title),
-                              self.white_space])
+            if height == None and width == None:
+                self.text.extend([self.white_space,
+                                  wikiutil.url_unquote(title),
+                                  self.white_space])
+            else:
+            #use ImageLink for resized images
+                if target == None:
+                    if alt == None or alt == '':
+                        self.text.extend([self.white_space,
+                                  "[[ImageLink(%(file)s,width=%(width)s,height=%(height)s)]]" % {
+                                    "file": wikiutil.url_unquote(title[len("attachment:"):]),
+                                    "width": width,
+                                    "height": height, },
+                                  self.white_space])
+                    else:
+                        self.text.extend([self.white_space,
+                                  "[[ImageLink(%(file)s,width=%(width)s,height=%(height)s,alt=%(alt)s)]]" % {
+                                    "file": wikiutil.url_unquote(title[len("attachment:"):]),
+                                    "width": width,
+                                    "height": height,
+                                    "alt": alt, },
+                                  self.white_space])
+                else:
+                    if alt == None or alt == '':
+                        self.text.extend([self.white_space,
+                                  "[[ImageLink(%(file)s,%(target)s,width=%(width)s,height=%(height)s)]]" % {
+                                    "file": wikiutil.url_unquote(title[len("attachment:"):]),
+                                    "target": target,
+                                    "width": width,
+                                    "height": height, },
+                                  self.white_space])
+                    else:
+                          self.text.extend([self.white_space,
+                                  "[[ImageLink(%(file)s,%(target)s,width=%(width)s,height=%(height)s,alt=%(alt)s)]]" % {
+                                    "file": wikiutil.url_unquote(title[len("attachment:"):]),
+                                    "target": target,
+                                    "width": width,
+                                    "height": height,
+                                    "alt": alt, },
+                                  self.white_space])
+
         # Drawing image
         elif title and title.startswith("drawing:"):
             self.text.extend([self.white_space,
--- a/MoinMoin/formatter/text_gedit.py	Sat Jan 06 12:01:25 2007 +0100
+++ b/MoinMoin/formatter/text_gedit.py	Sat Jan 06 15:27:29 2007 +0100
@@ -2,7 +2,7 @@
 """
     MoinMoin - "text/html+css" Formatter for feeding the GUI editor
 
-    @copyright: (c) Bastian Blank, Florian Festi, Thomas Waldmann
+    @copyright: (c) Bastian Blank, Florian Festi, Thomas Waldmann, Reimar Bauer
     @license: GNU GPL, see COPYING for details.
 """
 
@@ -93,7 +93,38 @@
     # Dynamic stuff / Plugins ############################################
 
     def macro(self, macro_obj, name, args):
-        if args is not None:
+        #use ImageLink for resized images
+        if name == "ImageLink" and args is not None:
+            pagename = self.page.page_name
+            if args:
+                args = args.split(',')
+                args = [arg.strip() for arg in args]
+            else:
+                args = []
+            argc = len(args)
+            url = args[0]
+            keywords = {}
+            width = None
+            height = None
+            alt = None
+            for arg in args:
+                if arg.find('=') > -1:
+                    key, value = arg.split('=')
+                    if key == 'width':
+                        width = value
+                    if key == 'height':
+                        height = value
+                    if key == 'alt':
+                        alt = value
+            target = None
+            if argc >= 2 and args[1]:
+                target = args[1]
+
+            return self.image(
+                    title="attachment:%s" % wikiutil.quoteWikinameURL(url),
+                    src=AttachFile.getAttachUrl(pagename, url, self.request, addts=1), width=width, height=height, alt=alt, target=target)
+
+        elif args is not None:
             result = "[[%s(%s)]]" % (name, args)
         else:
             result = "[[%s]]" % name