[pod] Take into account tabs. 'do ... from text' is now obsolete: pod expression now handle correctly tabs and carriage returns.

This commit is contained in:
Gaetan Delannay 2014-03-06 11:33:47 +01:00
parent e91a160924
commit ff102fbbe8
5 changed files with 1893 additions and 2023 deletions

View file

@ -189,7 +189,7 @@ class Buffer:
def dumpContent(self, content): def dumpContent(self, content):
'''Dumps string p_content into the buffer.''' '''Dumps string p_content into the buffer.'''
if self.pod: if self.pod:
# Take care of converting line breaks to odf line breaks. # Take care of converting line breaks and tabs.
content = escapeXml(content, format='odf', content = escapeXml(content, format='odf',
nsText=self.env.namespaces[self.env.NS_TEXT]) nsText=self.env.namespaces[self.env.NS_TEXT])
else: else:

View file

@ -89,6 +89,11 @@ f.close()
STYLES_POD_FONTS = '<@style@:font-face @style@:name="PodStarSymbol" ' \ STYLES_POD_FONTS = '<@style@:font-face @style@:name="PodStarSymbol" ' \
'@svg@:font-family="StarSymbol"/>' '@svg@:font-family="StarSymbol"/>'
# do ... \n from text(...) is obsolete.
OBSOLETE_RENDER_TEXT = 'Obsolete function. Use a pod expression instead ' \
'(field or track-changed). Now, a pod expression ' \
'handles carriage returns and tabs correctly.'
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
class Renderer: class Renderer:
templateTypes = ('odt', 'ods') # Types of POD templates templateTypes = ('odt', 'ods') # Types of POD templates
@ -259,11 +264,8 @@ class Renderer:
stylesMapping, self).run() stylesMapping, self).run()
def renderText(self, text, encoding='utf-8', stylesMapping={}): def renderText(self, text, encoding='utf-8', stylesMapping={}):
'''Method that can be used (under the name 'text') into a pod template '''Obsolete method.'''
for inserting a text containing carriage returns.''' raise Exception(OBSOLETE_RENDER_TEXT)
if text == None: text = ''
text = cgi.escape(text).replace('\r\n', '<br/>').replace('\n', '<br/>')
return self.renderXhtml(text, encoding, stylesMapping)
def evalIfExpression(self, condition, ifTrue, ifFalse): def evalIfExpression(self, condition, ifTrue, ifFalse):
'''This method implements the method 'test' which is proposed in the '''This method implements the method 'test' which is proposed in the

File diff suppressed because it is too large Load diff

View file

@ -340,6 +340,8 @@ class XhtmlEnvironment(XmlEnvironment):
# We remove leading and trailing carriage returns, but not # We remove leading and trailing carriage returns, but not
# whitespace because whitespace may be part of the text to dump. # whitespace because whitespace may be part of the text to dump.
contentSize = len(content) contentSize = len(content)
# We do not escape carriage returns, because, in XHTML, carriage
# returns are just ignorable white space.
self.dumpString(escapeXml(content)) self.dumpString(escapeXml(content))
self.currentContent = u'' self.currentContent = u''
# If we are within a table cell, update the total size of cell content. # If we are within a table cell, update the total size of cell content.

View file

@ -73,10 +73,10 @@ for k, v in htmlentitydefs.entitydefs.iteritems():
def escapeXml(s, format='xml', nsText='text'): def escapeXml(s, format='xml', nsText='text'):
'''Returns p_s, whose XML special chars have been replaced with escaped XML '''Returns p_s, whose XML special chars have been replaced with escaped XML
entities. If p_format is "odf", line breaks are converted to ODF line entities. If p_format is "odf", line breaks and tabs are converted to
breaks. In this case, it is needed to give the name of the "text" their ODF counterparts. In this case, it is needed to give the name of
namespace (p_nsText) as defined in the ODF document where the line breaks the "text" namespace (p_nsText) as defined in the ODF document where the
must be inserted.''' line breaks and tabs must be inserted.'''
if isinstance(s, unicode): if isinstance(s, unicode):
res = u'' res = u''
else: else:
@ -88,6 +88,8 @@ def escapeXml(s, format='xml', nsText='text'):
res += XML_SPECIAL_CHARS_NO_APOS[c] res += XML_SPECIAL_CHARS_NO_APOS[c]
elif odf and (c == '\n'): elif odf and (c == '\n'):
res += '<%s:line-break/>' % nsText res += '<%s:line-break/>' % nsText
elif odf and (c == '\t'):
res += '<%s:tab/>' % nsText
elif odf and (c == '\r'): elif odf and (c == '\r'):
pass pass
else: else: