[pod] Line breaks which are found within pod expression results are converted to odf line-breaks into the pod result.
This commit is contained in:
parent
244826194b
commit
06039b300c
|
@ -55,7 +55,7 @@ class BufferAction:
|
|||
self.fromExprResult = None
|
||||
# When an error is encountered, must we raise it or write it into the
|
||||
# buffer?
|
||||
self.raiseErrors = self.buffer.caller() == 'px'
|
||||
self.raiseErrors = self.buffer.caller == 'px'
|
||||
|
||||
def getExceptionLine(self, e):
|
||||
'''Gets the line describing exception p_e, containing the pathname of
|
||||
|
@ -66,7 +66,7 @@ class BufferAction:
|
|||
'''Write the encountered error into the buffer or raise an exception
|
||||
if self.raiseErrors is True.'''
|
||||
if self.raiseErrors:
|
||||
if self.buffer.caller() == 'px':
|
||||
if self.buffer.caller == 'px':
|
||||
# Add in the error message the line nb where the errors occurs
|
||||
# within the PX.
|
||||
locator = self.buffer.env.parser.locator
|
||||
|
|
|
@ -121,6 +121,8 @@ class Buffer:
|
|||
self.parent = parent
|
||||
self.subBuffers = {} # ~{i_bufferIndex: Buffer}~
|
||||
self.env = env
|
||||
# Are we computing for pod or for px ?
|
||||
self.caller= (env.__class__.__name__=='PxEnvironment') and 'px' or 'pod'
|
||||
|
||||
def addSubBuffer(self, subBuffer=None):
|
||||
if not subBuffer:
|
||||
|
@ -182,7 +184,13 @@ class Buffer:
|
|||
|
||||
def dumpContent(self, content):
|
||||
'''Dumps string p_content into the buffer.'''
|
||||
self.write(escapeXml(content))
|
||||
if self.caller == 'pod':
|
||||
# Take care of converting line breaks to odf line breaks.
|
||||
content = escapeXml(content, format='odf',
|
||||
nsText=self.env.namespaces[self.env.NS_TEXT])
|
||||
else:
|
||||
content = escapeXml(content)
|
||||
self.write(content)
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
class FileBuffer(Buffer):
|
||||
|
@ -635,7 +643,7 @@ class MemoryBuffer(Buffer):
|
|||
if escape: result.dumpContent(res)
|
||||
else: result.write(res)
|
||||
except Exception, e:
|
||||
if self.caller() == 'pod':
|
||||
if self.caller == 'pod':
|
||||
PodError.dump(result, EVAL_EXPR_ERROR % (
|
||||
evalEntry.expr, e), dumpTb=False)
|
||||
else: # px
|
||||
|
@ -654,9 +662,4 @@ class MemoryBuffer(Buffer):
|
|||
def clean(self):
|
||||
'''Cleans the buffer content.'''
|
||||
self.content = u''
|
||||
|
||||
def caller(self):
|
||||
'''Returns "pod" if the caller is appy.pod, "px" if it is appy.px.'''
|
||||
if self.env.__class__.__name__ == 'PxEnvironment': return 'px'
|
||||
return 'pod'
|
||||
# ------------------------------------------------------------------------------
|
||||
|
|
|
@ -66,16 +66,24 @@ for k, v in htmlentitydefs.entitydefs.iteritems():
|
|||
if not HTML_ENTITIES.has_key(k) and not XML_ENTITIES.has_key(k):
|
||||
HTML_ENTITIES[k] = ''
|
||||
|
||||
def escapeXml(s):
|
||||
def escapeXml(s, format='xml', nsText='text'):
|
||||
'''Returns p_s, whose XML special chars have been replaced with escaped XML
|
||||
entities.'''
|
||||
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.'''
|
||||
if isinstance(s, unicode):
|
||||
res = u''
|
||||
else:
|
||||
res = ''
|
||||
odf = format == 'odf'
|
||||
for c in s:
|
||||
if XML_SPECIAL_CHARS.has_key(c):
|
||||
res += XML_SPECIAL_CHARS[c]
|
||||
elif odf and (c == '\n'):
|
||||
res += '<%s:line-break/>' % nsText
|
||||
elif odf and (c == '\r'):
|
||||
pass
|
||||
else:
|
||||
res += c
|
||||
return res
|
||||
|
|
Loading…
Reference in a new issue