Edgewall Software

MacroBazaar: WikiInclude.2.py

File WikiInclude.2.py, 0.6 kB (added by anthony.vito@…, 3 years ago)

Updated for the new formatter API of .9 pre

Line 
1from StringIO import StringIO
2from trac.wiki.formatter import wiki_to_html
3
4def execute(hdf, txt, env):
5        db = env.get_db_cnx()
6        out = StringIO()
7       
8        txt = txt or ''
9        args = txt.split('|')
10        name = args.pop(0).replace('\'', '\'\'')
11        sql = "SELECT text from wiki where name = '%s' order by version desc limit 1" % name
12        cs = db.cursor()
13        cs.execute(sql)
14       
15        row = cs.fetchone()
16        if row == None:
17                return ''
18        text = row[0]
19       
20        i = 0
21        for arg in args:
22                text = text.replace('{{%d}}' % (i+1), args[i])
23                i += 1
24       
25        out.write(wiki_to_html(text, env, None))
26       
27        return out.getvalue()