Package omeroweb :: Package webgateway :: Package templatetags :: Module wikitags
[hide private]
[frames] | no frames]

Source Code for Module omeroweb.webgateway.templatetags.wikitags

  1  #!/usr/bin/env python 
  2  # -*- coding: utf-8 -*- 
  3  #  
  4  #  
  5  #  
  6  # Copyright (c) 2008 University of Dundee.  
  7  #  
  8  # This program is free software: you can redistribute it and/or modify 
  9  # it under the terms of the GNU Affero General Public License as 
 10  # published by the Free Software Foundation, either version 3 of the 
 11  # License, or (at your option) any later version. 
 12  #  
 13  # This program is distributed in the hope that it will be useful, 
 14  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 16  # GNU Affero General Public License for more details. 
 17  #  
 18  # You should have received a copy of the GNU Affero General Public License 
 19  # along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 20  #  
 21  # Author: Aleksandra Tarkowska <A(dot)Tarkowska(at)dundee(dot)ac(dot)uk>, 2008. 
 22  #  
 23  # Version: 1.0 
 24  # 
 25   
 26  import re 
 27   
 28  from django.template import Library 
 29  from django.conf import settings 
 30  from django.core.urlresolvers import reverse 
 31  from django.templatetags.static import PrefixNode 
 32   
 33  register = Library() 
34 35 @register.filter 36 -def wikify(value):
37 if value is not None: 38 39 urlier = r'(http[s]?://|localhost|ftp://|ftps://)(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\)\|,]|(?:%[0-9a-fA-F][0-9a-fA-F]))+' 40 wikifier = re.compile(r'\b(%s)\b' % urlier, re.IGNORECASE) 41 value = wikifier.sub(r'<a href="\1" target="_blank">\1</a>', value) 42 43 return value 44 45 return value
46
47 # happy :) :-) 48 # wink ;) ;-) 49 # big smile :-D :D 50 # tongue sticking out :-P :P :-p :p 51 # surprised / o, no :-o :O 52 # sad :( :-( 53 # very sad :-(( :(( 54 # embarrassed :"> 55 # wearing sunglasses B-) 56 # kiss =* :-* :* 57 # confused :-/ :-\ 58 # angry X-( x-( X( x( 59 60 61 @register.filter 62 -def sharewikify(value):
63 if value is not None: 64 65 WIKI_WORD = r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\)\|,]|(?:%[0-9a-fA-F][0-9a-fA-F]))+' 66 wikifier = re.compile(r'\b(%s)\b' % WIKI_WORD) 67 value = wikifier.sub(r'<a href="\1" target="_blank">\1</a>', value) 68 69 # happy :) :-) 70 emot1 = re.compile(r'\:[\-]?\)', re.VERBOSE) 71 value = emot1.sub(r'<img src="%simage/emots/tinymce_smiley-smile18.gif" />' % PrefixNode.handle_simple("STATIC_URL"), value) 72 73 # wink ;) ;-) 74 emot11 = re.compile(r'\;[\-]?\)', re.VERBOSE) 75 value = emot11.sub(r'<img src="%simage/emots/tinymce_smiley-wink18.gif" />' % PrefixNode.handle_simple("STATIC_URL"), value) 76 77 # very sad :-(( :(( 78 emot22 = re.compile(r'\:[\-]?\(\(', re.VERBOSE) 79 value = emot22.sub(r'<img src="%simage/emots/tinymce_smiley-cry18.gif" />' % PrefixNode.handle_simple("STATIC_URL"), value) 80 81 # sad :( :-( 82 emot2 = re.compile(r'\:[\-]?\(', re.VERBOSE) 83 value = emot2.sub(r'<img src="%simage/emots/tinymce_smiley-frown18.gif" />' % PrefixNode.handle_simple("STATIC_URL"), value) 84 85 # kiss =* :-* :* 86 emot3 = re.compile(r'[=\:][\-]?\*', re.VERBOSE) 87 value = emot3.sub(r'<img src="%simage/emots/tinymce_smiley-kiss18.gif" />' % PrefixNode.handle_simple("STATIC_URL"), value) 88 89 # big smile :-D :D 90 emot4 = re.compile(r'\:[\-]?[dD]', re.VERBOSE) 91 value = emot4.sub(r'<img src="%simage/emots/tinymce_smiley-laughing18.gif" />' % PrefixNode.handle_simple("STATIC_URL"), value) 92 93 # tongue sticking out :-P :P :-p :p 94 emot5 = re.compile(r'\:[\-]?[pP]', re.VERBOSE) 95 value = emot5.sub(r'<img src="%simage/emots/tinymce_smiley-tongue-out18.gif" />' % PrefixNode.handle_simple("STATIC_URL"), value) 96 97 # surprised / o, no :-o :O 98 emot6 = re.compile(r'\:[\-]?[oO]', re.VERBOSE) 99 value = emot6.sub(r'<img src="%simage/emots/tinymce_smiley-surprised18.gif" />' % PrefixNode.handle_simple("STATIC_URL"), value) 100 101 # embarrassed :"> 102 emot7 = re.compile(r'\:\"\>', re.VERBOSE) 103 value = emot7.sub(r'<img src="%simage/emots/tinymce_smiley-embarassed18.gif" />' % PrefixNode.handle_simple("STATIC_URL"), value) 104 105 # wearing sunglasses B-) 106 emot8 = re.compile(r'B\-\)', re.VERBOSE) 107 value = emot8.sub(r'<img src="%simage/emots/tinymce_smiley-cool18.gif" />' % PrefixNode.handle_simple("STATIC_URL"), value) 108 109 # confused :-/ :-\ 110 emot9 = re.compile(r'\:\-[\\/]', re.VERBOSE) 111 value = emot9.sub(r'<img src="%simage/emots/tinymce_smiley-undecided18.gif" />' % PrefixNode.handle_simple("STATIC_URL"), value) 112 113 # angry X-( x-( X( x( 114 emot9 = re.compile(r'[xX][\-]?\(', re.VERBOSE) 115 value = emot9.sub(r'<img src="%simage/emots/tinymce_smiley-yell18.gif" />' % PrefixNode.handle_simple("STATIC_URL"), value) 116 117 # TODO: Beta 4.1 118 #quote = re.compile(r'\[quote\](.*)\[/quote\]', re.DOTALL) 119 #value = quote.sub(r'<p class="quote">\1</p>', value) 120 121 return value
122 123 # happy :) :-) 124 # wink ;) ;-) 125 # big smile :-D :D 126 # tongue sticking out :-P :P :-p :p 127 # surprised / o, no :-o :O 128 # sad :( :-( 129 # very sad :-(( :(( 130 # embarrassed :"> 131 # wearing sunglasses B-) 132 # kiss =* :-* :* 133 # confused :-/ :-\ 134 # angry X-( x-( X( x( 135