from __main__ import * from __main__ import _resolve_url import __main__; __main__.style_sheet += u"""\ """ __all__ = [ 'markup_clear', 'markup_rightthumb', 'markup_leftthumb', 'markup_rightimage', 'markup_leftimage', 'context_rightthumb', 'context_leftthumb', 'context_rightimage', 'context_leftimage', 'markup_image', 'context_image', ] zoom_image = "http://craie.unpy.net/aetest/index.cgi-files/default/zoom.png" import Image, commands, sys def _resolve_file(meta, url, page, file): """ Helper for markup_image url, page, file are html returns the local path, if any""" if page != None: page = page.strip() correct_page = correct_case( unquote_html(page) ) if file != None: file = file.strip() if url != None: return None else: if page is None: page = meta['name'] if file != None: return path.join(file_dir, page, file) return None image_size_cache = {} def image_size(f): if not image_size_cache.has_key(f): try: image_size_cache[f] = Image.open(f).size except IOError: image_size_cache[f] = None return image_size_cache[f] context_image = ['url','page','file','title'] def markup_image(text, meta, url=None, page=None, file=None, title=None): """ Insert an image. Parameters as per [link]. """ local_file = _resolve_file(meta, url, page, file) text, url = _resolve_url(text, meta, url, page, file, True) geometry = local_file and image_size(local_file) if geometry != None: size = " width=%s height=%s" % geometry else: size = "" if title == None: title = u'' else: title = u' title="' + quote_html(title) + '"' return u'' def common(side, zooms, text, caption, thumbext, meta): image = unquote_html(text).strip() basename, ext = os.path.splitext(image) thumb = basename + '-small' + (thumbext or ext) caption = caption or basename result = ['[html ]'] sz = image_size(_resolve_file(meta, None, None, zooms and thumb or image)) width = max(100, sz and sz[0] or 300) def link(s): return '[link [file ' + image + '] ' + s + ']' if zooms: result.append('[link [file ' + image + '] ') result.append('[html
]') if zooms: result.append(link('[image [file ' + thumb + ']]')) result.append("[html
]") result.append("[html
]" + link("[html ]") + "[html
]") if caption: result.append(link(caption)) result.append("[html
]") else: result.append('[image [file ' + image + ']][line]') if caption: result.append("[html
]" + caption + "[html
]") result.append("[html
]") if zooms: result.append(']') return markup(''.join(result), meta, False) context_rightthumb = ['caption', 'thumbext'] def markup_rightthumb(text, meta, caption = u"", thumbext=None): """ Insert a right-hand thumbnail floating image. The image must be attached to the current page. Optional parameters: caption - a caption for the image thumbext - extension of the thumbnail (eg .jpg) The thumbnail has the same basename as the full-size image with -small appended. If [thumbext] is specified, that is the extension of the thumbnail. Otherwise, the extension is the same as the full-size image.""" return common("right", True, text, caption,thumbext, meta) context_leftthumb = ['caption', 'thumbext'] def markup_leftthumb(text, meta, caption = u"", thumbext=None): """ Insert a left-hand floating thumbnail image. The image must be attached to the current page. Optional parameters: caption - a caption for the image thumbext - extension of the thumbnail (eg .jpg) The thumbnail has the same basename as the full-size image with -small appended. If [thumbext] is specified, that is the extension of the thumbnail. Otherwise, the extension is the same as the full-size image.""" return common("left", True, text, caption,thumbext, meta) context_rightimage = ['caption', 'thumbext'] def markup_rightimage(text, meta, caption = u"", thumbext=None): """ Insert a right-hand floating image. The image must be attached to the current page. Optional parameters: caption - a caption for the image""" return common("right", False, text, caption,thumbext, meta) context_leftimage = ['caption', 'thumbext'] def markup_leftimage(text, meta, caption = u"", thumbext=None): """ Insert a left-hand floating image. The image must be attached to the current page. Optional parameters: caption - a caption for the image""" return common("right", False, text, caption,thumbext, meta) return common("left", False, text, caption,thumbext, meta) def markup_clear(text, meta): text = text or 'both' return '
' # vim:sw=4:sts=4:et