Show
Ignore:
Timestamp:
07/23/08 13:10:41 (20 months ago)
Author:
JensDiemer
Message:

blog plugin: use a simple markup for comments: ticket:213

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/pylucid/PyLucid/tools/content_processors.py

    r1634 r1709  
    2121""" 
    2222 
     23import re 
     24 
     25if __name__ == "__main__": 
     26    # For doctest only 
     27    import os 
     28    os.environ["DJANGO_SETTINGS_MODULE"] = "PyLucid.settings" 
     29 
    2330from django.conf import settings 
    2431from django.template import Template, Context 
     
    3643# MARKUP 
    3744 
     45BLOCK_RE = re.compile("\n{2,}") 
     46 
     47LINK_RE = re.compile( 
     48    r'''(?<!=")(?P<url>(http|ftp|svn|irc)://(?P<title>[^\s\<]+))(?uimx)''' 
     49) 
     50 
    3851def fallback_markup(content): 
    3952    """ 
    4053    A simplest markup, build only paragraphs. 
     54    >>> fallback_markup("line one\\nline two\\n\\nnext block") 
     55    '<p>line one<br />\\nline two</p>\\n\\n<p>next block</p>' 
     56 
     57    >>> fallback_markup("url: http://pylucid.org END") 
     58    '<p>url: <a href="http://pylucid.org">pylucid.org</a> END</p>' 
    4159    """ 
    42     import re 
    4360    content = content.replace("\r\n", "\n").replace("\r","\n") 
    44     blocks = re.split("\n{2,}", content) 
     61    blocks = BLOCK_RE.split(content) 
    4562    blocks = [line.replace("\n", "<br />\n") for line in blocks] 
    4663    content = "<p>" + "</p>\n\n<p>".join(blocks) + "</p>" 
     64    content = LINK_RE.sub(r'<a href="\g<url>">\g<title></a>', content) 
    4765    return content 
    4866 
     
    156174 
    157175 
    158  
     176if __name__ == "__main__": 
     177    import doctest 
     178    doctest.testmod( 
     179#        verbose=True 
     180        verbose=False 
     181    ) 
     182    print "DocTest end."