ó
rBÛ[c           @   sE   d  Z  d d l m Z d d l Z d d l Z d d d „  ƒ  YZ d S(   sq    WikiFormatter class
    If you want to implement new Formatter: extend this class and overwrite format method. 
iÿÿÿÿ(   t   ConfigNt   WikiFormatterc           B   s    e  Z d  Z d „  Z d „  Z RS(   s|   Formatter for wiki content
       'DataStore' object must be added to Config before, instanciating object of this class
    c         C   s   t  j d ƒ |  _ d S(   s   Initilize WikiFormatter
           'DataStore' object must be added to Config before, instanciating object of this class
        t	   DataStoreN(   R    t   gett	   datastore(   t   self(    (    s"   lib/medus/content/WikiFormatter.pyt   __init__   s    c            sd   t  d „  d- d. d/ d0 d1 d2 d3 d4 d ‡  f d †  f d5 d6 d7 d8 d9 d: d; d< d= d> d? d@ dA f | ƒ S(B   s.   Return formatted wiki content, (s) - file namec         S   s   t  j d | d | d |  ƒ S(   Ns   (?m)i    i   (   t   ret   sub(   t   st   r(    (    s"   lib/medus/content/WikiFormatter.pyt   <lambda>   s    s   ^! (.*)$s   <h1>\g<1></h1>s	   ^!! (.*)$s   <h2>\g<1></h2>s
   ^!!! (.*)$s   <h3>\g<1></h3>s.   \{(([^|]+).(gif|jpg|jpe|jpeg|png))\|([^\}]+)\}s*   <img src="\g<1>" alt="\g<2>" border="0" />s3   \[((http|https|ftp|mailto|news):[^\]]*)\|([^\]]+)\]s   <a href="\g<1>">\g<3></a>s   \[(\?[^\]]*)\|([^\]]+)\]s   <a href="\g<1>">\g<2></a>s   \'{3}(.+?)\'{3}s   <b>\g<1></b>s   \'{2}(.+?)\'{2}s   <em>\g<1></em>s4   (?<!\!|\"|\>|\#|\=|\/|\?)\b[A-Z][a-z]+([A-Z][a-z]+)+c            si   d |  j  d ƒ d |  j  d ƒ d d f d |  j  d ƒ d d |  j  d ƒ f f ˆ  j j |  j  d ƒ ƒ S(   Ns   %s<a href='?%s%s%s'>%s</a>i    s   wn=s   &amp;job=editt   ?t    (   t   groupR   t   exists(   t   m(   R   (    s"   lib/medus/content/WikiFormatter.pyR   %   s    $'s   ^\*\ (.*?)$s   <ul><li>\g<1></li></ul>s   ^\*\*\ (.*?)$s    <ul><ul><li>\g<1></li></ul></ul>s   ^\*\*\*\ (.*?)$s)   <ul><ul><ul><li>\g<1></li></ul></ul></ul>s   <\/ul>\r*(\n)<ul>s   \g<1>s   ^\#\ (.*?)$s   <ol><li>\g<1></li></ol>s   ^\#\#\ (.*?)$s    <ol><ol><li>\g<1></li></ol></ol>s   ^\#\#\#\ (.*?)$s)   <ol><ol><ol><li>\g<1></li></ol></ol></ol>s   <\/ol>\r*(\n)<ol>s	   ^ +(.*)\ns   <pre>\g<0></pre>s   </pre><pre>R   s	   -{4,}\r\ns   <hr />s   (?<!\")(ht|f)tp:[^<>"\s]+s   <a href="\g<0>">\g<0></a>s   \r\ns   <br />(   s   ^! (.*)$s   <h1>\g<1></h1>(   s	   ^!! (.*)$s   <h2>\g<1></h2>(   s
   ^!!! (.*)$s   <h3>\g<1></h3>(   s.   \{(([^|]+).(gif|jpg|jpe|jpeg|png))\|([^\}]+)\}s*   <img src="\g<1>" alt="\g<2>" border="0" />(   s3   \[((http|https|ftp|mailto|news):[^\]]*)\|([^\]]+)\]s   <a href="\g<1>">\g<3></a>(   s   \[(\?[^\]]*)\|([^\]]+)\]s   <a href="\g<1>">\g<2></a>(   s   \'{3}(.+?)\'{3}s   <b>\g<1></b>(   s   \'{2}(.+?)\'{2}s   <em>\g<1></em>(   s   ^\*\ (.*?)$s   <ul><li>\g<1></li></ul>(   s   ^\*\*\ (.*?)$s    <ul><ul><li>\g<1></li></ul></ul>(   s   ^\*\*\*\ (.*?)$s)   <ul><ul><ul><li>\g<1></li></ul></ul></ul>(   s   <\/ul>\r*(\n)<ul>s   \g<1>(   s   ^\#\ (.*?)$s   <ol><li>\g<1></li></ol>(   s   ^\#\#\ (.*?)$s    <ol><ol><li>\g<1></li></ol></ol>(   s   ^\#\#\#\ (.*?)$s)   <ol><ol><ol><li>\g<1></li></ol></ol></ol>(   s   <\/ol>\r*(\n)<ol>s   \g<1>(   s	   ^ +(.*)\ns   <pre>\g<0></pre>(   s   </pre><pre>R   (   s	   -{4,}\r\ns   <hr />(   s   (?<!\")(ht|f)tp:[^<>"\s]+s   <a href="\g<0>">\g<0></a>(   s   \r\ns   <br />(   t   reduce(   R   R	   (    (   R   s"   lib/medus/content/WikiFormatter.pyt   format   s0    	(   t   __name__t
   __module__t   __doc__R   R   (    (    (    s"   lib/medus/content/WikiFormatter.pyR   	   s   	(    (   R   t	   medus.cfgR    t   cgiR   R   (    (    (    s"   lib/medus/content/WikiFormatter.pyt   <module>   s   