[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:
parent
e91a160924
commit
ff102fbbe8
|
@ -189,7 +189,7 @@ class Buffer:
|
|||
def dumpContent(self, content):
|
||||
'''Dumps string p_content into the buffer.'''
|
||||
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',
|
||||
nsText=self.env.namespaces[self.env.NS_TEXT])
|
||||
else:
|
||||
|
|
|
@ -89,6 +89,11 @@ f.close()
|
|||
STYLES_POD_FONTS = '<@style@:font-face @style@:name="PodStarSymbol" ' \
|
||||
'@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:
|
||||
templateTypes = ('odt', 'ods') # Types of POD templates
|
||||
|
@ -259,11 +264,8 @@ class Renderer:
|
|||
stylesMapping, self).run()
|
||||
|
||||
def renderText(self, text, encoding='utf-8', stylesMapping={}):
|
||||
'''Method that can be used (under the name 'text') into a pod template
|
||||
for inserting a text containing carriage returns.'''
|
||||
if text == None: text = ''
|
||||
text = cgi.escape(text).replace('\r\n', '<br/>').replace('\n', '<br/>')
|
||||
return self.renderXhtml(text, encoding, stylesMapping)
|
||||
'''Obsolete method.'''
|
||||
raise Exception(OBSOLETE_RENDER_TEXT)
|
||||
|
||||
def evalIfExpression(self, condition, ifTrue, ifFalse):
|
||||
'''This method implements the method 'test' which is proposed in the
|
||||
|
|
3890
pod/test/Tests.rtf
3890
pod/test/Tests.rtf
File diff suppressed because it is too large
Load diff
|
@ -340,6 +340,8 @@ class XhtmlEnvironment(XmlEnvironment):
|
|||
# We remove leading and trailing carriage returns, but not
|
||||
# whitespace because whitespace may be part of the text to dump.
|
||||
contentSize = len(content)
|
||||
# We do not escape carriage returns, because, in XHTML, carriage
|
||||
# returns are just ignorable white space.
|
||||
self.dumpString(escapeXml(content))
|
||||
self.currentContent = u''
|
||||
# If we are within a table cell, update the total size of cell content.
|
||||
|
|
|
@ -73,10 +73,10 @@ for k, v in htmlentitydefs.entitydefs.iteritems():
|
|||
|
||||
def escapeXml(s, format='xml', nsText='text'):
|
||||
'''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
|
||||
breaks. In this case, it is needed to give the name of the "text"
|
||||
namespace (p_nsText) as defined in the ODF document where the line breaks
|
||||
must be inserted.'''
|
||||
entities. If p_format is "odf", line breaks and tabs are converted to
|
||||
their ODF counterparts. In this case, it is needed to give the name of
|
||||
the "text" namespace (p_nsText) as defined in the ODF document where the
|
||||
line breaks and tabs must be inserted.'''
|
||||
if isinstance(s, unicode):
|
||||
res = u''
|
||||
else:
|
||||
|
@ -88,6 +88,8 @@ def escapeXml(s, format='xml', nsText='text'):
|
|||
res += XML_SPECIAL_CHARS_NO_APOS[c]
|
||||
elif odf and (c == '\n'):
|
||||
res += '<%s:line-break/>' % nsText
|
||||
elif odf and (c == '\t'):
|
||||
res += '<%s:tab/>' % nsText
|
||||
elif odf and (c == '\r'):
|
||||
pass
|
||||
else:
|
||||
|
|
Loading…
Reference in a new issue