30
30
from reportlab.lib.utils import ImageReader
32
32
_regex = re.compile('\[\[(.+?)\]\]')
33
utils._regex = re.compile('\[\[\s*(.+?)\s*\]\]',re.DOTALL)
34
34
class html2html(object):
35
35
def __init__(self, html, localcontext):
36
36
self.localcontext = localcontext
47
47
new_node.append(new_child)
49
49
for n in new_child:
50
new_child.text = utils._process_text(self, child.text)
51
new_child.tail = utils._process_text(self, child.tail)
50
52
new_child.remove(n)
51
53
process_text(child, new_child)
58
60
output = cStringIO.StringIO(base64.decodestring(src))
59
61
img = ImageReader(output)
60
62
(width,height) = img.getSize()
61
new_child.set('width',str(width))
62
new_child.set('height',str(height))
63
if not new_child.get('width'):
64
new_child.set('width',str(width))
65
if not new_child.get('height') :
66
new_child.set('height',str(height))
64
68
new_child.getparent().remove(new_child)
65
69
new_child.text = utils._process_text(self, child.text)
70
new_child.tail = utils._process_text(self, child.tail)
66
71
self._node = copy.deepcopy(self.etree)
67
72
for n in self._node:
68
73
self._node.remove(n)
69
74
process_text(self.etree, self._node)
77
def url_modify(self,root):
78
for n in root.getchildren():
79
if (n.text.find('<a ')>=0 or n.text.find('<a')>=0) and n.text.find('href')>=0 and n.text.find('style')<=0 :
80
node = (n.tag=='span' and n.getparent().tag=='u') and n.getparent().getparent() or ((n.tag=='span') and n.getparent()) or n
81
style = node.get('color') and "style='color:%s; text-decoration: none;'"%node.get('color') or ''
82
if n.text.find('<a')>=0:
86
href = n.text.split(t)[-1]
87
n.text = ' '.join([t,style,href])
72
91
def parseString(node, localcontext = {}):
73
92
r = html2html(node, localcontext)
94
root = r.url_modify(root)