| 1 |
rom trac.wiki.macros import WikiMacroBase |
|---|
| 2 |
from trac.util import escape |
|---|
| 3 |
from StringIO import StringIO |
|---|
| 4 |
import csv |
|---|
| 5 |
|
|---|
| 6 |
class CSVMacro(WikiMacroBase): |
|---|
| 7 |
''' |
|---|
| 8 |
0.11 Port of CSV Macro. |
|---|
| 9 |
See http://trac-hacks.org/wiki/CsvMacro |
|---|
| 10 |
''' |
|---|
| 11 |
|
|---|
| 12 |
def render_macro(self, req, name, content): |
|---|
| 13 |
sniffer = csv.Sniffer() |
|---|
| 14 |
content = content.encode('ascii', 'replace') |
|---|
| 15 |
reader = csv.reader(StringIO(content), sniffer.sniff(content)) |
|---|
| 16 |
out = StringIO() |
|---|
| 17 |
out.write('<table class="wiki">\n') |
|---|
| 18 |
for row in reader: |
|---|
| 19 |
out.write('<tr>') |
|---|
| 20 |
for col in row: |
|---|
| 21 |
out.write('<td>%s</td>' % escape(col)) |
|---|
| 22 |
out.write('</tr>\n') |
|---|
| 23 |
out.write('</table>\n') |
|---|
| 24 |
return out.getvalue() |
|---|