constance

Scripts for generating (an earlier obsolete version of) my personal web site
git clone https://code.djc.id.au/git/constance/

viewutils.py (969B) - raw

      1 import re, urllib
      2 from markdown2 import Markdown
      3 import genshi
      4 
      5 def markdown(s, safe_mode=None):
      6     m = Markdown(extras=['code_friendly'], safe_mode=safe_mode).convert(s)
      7     return genshi.Markup(m)
      8 
      9 def mini_markdown(s, safe_mode=None):
     10     # XXX find a more efficient way to do this?
     11     m = Markdown(extras=['code_friendly']).convert(s)
     12     match = re.match(u'<p>(.*)</p>', m)
     13     assert match, m
     14     return genshi.Markup(match.group(1))
     15 
     16 IDIFY_WHITESPACE_PATT = re.compile(r'(?u)\s+')
     17 IDIFY_ACCEPT_PATT = re.compile(r'(?u)\w|[-_]')
     18 def idify(s):
     19     # http://www.w3.org/TR/REC-xml/#NT-Name
     20     s = s.lower()
     21     s = IDIFY_WHITESPACE_PATT.sub(u'-', s)
     22     return u''.join(c for c in s if IDIFY_ACCEPT_PATT.match(c))
     23 
     24 ATOM_TIME_FORMAT = '%Y-%m-%dT%H:%M:%S+10:00'
     25 
     26 def tag_list(tags):
     27     return genshi.Markup(u', ').join([
     28             genshi.Markup(u'<a rel="tag" href="/tags/%s">%s</a>' % (urllib.quote(tag.encode('utf8'), ''), tag)) 
     29             for tag in tags])