2 # -*- coding: utf-8 -*-
8 from urlparse import urlparse
10 from lxml.builder import ElementMaker
11 from treecutter import constants as const
14 db = ElementMaker(namespace=const.DB_NS, nsmap=const.NSMAP)
15 r = re.search(r"(?P<url>https?://[^ ]+)\|(?P<title>[\w\-\.]+)", text)
17 rep = r.groups(r.group(1))
18 text = db.link(rep[1],**{const.XLINK+"href": rep[0]})
22 def __init__(self, tablefile, title):
23 self.tablefile = tablefile
28 f = codecs.open(self.tablefile, encoding='utf-8')
30 c = re.split(r'\t+', line.rstrip())
34 db = ElementMaker(namespace=const.DB_NS, nsmap=const.NSMAP)
36 nrcol = str(len(cols[0]))
37 if cols[0][0][0] == '*':
38 cols[0][0] = cols[0][0][1:]
42 row.append(db.entry(linkify(e), align="center"))
49 row.append(db.entry(linkify(e)))
50 tab = db.table(db.title(self.title),
51 db.tgroup(head,body,cols=nrcol,
52 colsep='1',rowsep='1',align='left'),
56 if __name__ == "__main__":
57 for arg in sys.argv[1:]:
62 argument = al[1].decode('utf-8')
64 (tablefile, title) = argument.split('|')
65 tab = Table(tablefile,title)
69 sys.stdout.write(etree.tostring(txml,encoding='UTF-8',pretty_print=False))