appy.shared.diff: bugfix: work internally on unicode representations of strings to diff: this way, we are sure every char is one char length.

This commit is contained in:
Gaetan Delannay 2012-04-13 18:07:48 +02:00
parent 40e8a5f258
commit abdd0ee52d
4 changed files with 19 additions and 7 deletions

View file

@ -189,7 +189,8 @@
<table width="100%" class="summary">
<tr>
<tal:comment replace="nothing">Title</tal:comment>
<td colspan="2" class="objectTitle" tal:content="contextObj/title_or_id"></td>
<td colspan="2" class="objectTitle"
tal:content="python: contextObj.getFieldValue('title', layoutType='view')"></td>
</tr>
<tr class="underTitle">
<td colspan="2" class="by">

View file

@ -31,11 +31,11 @@ class OdtTable:
self.html = html
def dumpCell(self, content, span=1, header=False,
paraStyle=None, cellStyle=None):
paraStyle=None, cellStyle=None, align=None):
'''Dumps a cell in the table. If no specific p_paraStyle (p_cellStyle)
is given, self.paraStyle (self.cellStyle) is used, excepted if
p_header is True: in that case, self.paraHeaderStyle
(self.cellHeaderStyle) is used.'''
(self.cellHeaderStyle) is used. p_align is used only for HTML.'''
if not paraStyle:
if header: paraStyle = self.paraHeaderStyle
else: paraStyle = self.paraStyle
@ -52,8 +52,10 @@ class OdtTable:
self.res += '</%stable-cell>' % self.tns
else:
tag = header and 'th' or 'td'
self.res += '<%s colspan="%d">%s</%s>' % \
(tag, span, cgi.escape(str(content)), tag)
palign = ''
if align: palign = ' align="%s"' % align
self.res += '<%s colspan="%d"%s>%s</%s>' % \
(tag, span, palign, cgi.escape(str(content)), tag)
def startRow(self):
if not self.html:

View file

@ -16,6 +16,7 @@ mimeTypesExts = {
'application/pdf' : 'pdf',
'image/png' : 'png',
'image/jpeg' : 'jpg',
'image/pjpeg' : 'jpg',
'image/gif' : 'gif'
}
xmlPrologue = '<?xml version="1.0" encoding="utf-8" ?>\n'

View file

@ -245,19 +245,27 @@ class HtmlDiff:
deleteStyle = 'color: red; text-decoration: line-through; cursor: help'
def __init__(self, old, new,
insertMsg='Inserted text', deleteMsg='Deleted text',
insertMsg=u'Inserted text', deleteMsg=u'Deleted text',
insertCss=None, deleteCss=None, insertName='insert',
deleteName='delete', diffRatio=0.7):
# p_old and p_new are strings containing chunks of HTML.
# p_old and p_new are strings containing chunks of HTML. If they are not
# unicode strings, we convert them to unicode; this way, every char is
# only one char lenght.
self.old = old.strip()
if isinstance(self.old, str): self.old = self.old.decode('utf-8')
self.new = new.strip()
if isinstance(self.new, str): self.new = self.new.decode('utf-8')
# Every time an "insert" or "delete" difference will be detected from
# p_old to p_new, the impacted chunk will be surrounded by a tag that
# will get, respectively, a 'title' attribute filled p_insertMsg or
# p_deleteMsg. The message will give an explanation about the change
# (who made it and at what time, for example).
self.insertMsg = insertMsg
if isinstance(self.insertMsg, str):
self.insertMsg = self.insertMsg.decode('utf-8')
self.deleteMsg = deleteMsg
if isinstance(self.deleteMsg, str):
self.deleteMsg = self.deleteMsg.decode('utf-8')
# This tag will get a CSS class p_insertCss or p_deleteCss for
# highlighting the change. If no class is provided, default styles will
# be used (see HtmlDiff.insertStyle and HtmlDiff.deleteStyle).