[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
|
self.fromExprResult = None
|
||||||
# When an error is encountered, must we raise it or write it into the
|
# When an error is encountered, must we raise it or write it into the
|
||||||
# buffer?
|
# buffer?
|
||||||
self.raiseErrors = self.buffer.caller() == 'px'
|
self.raiseErrors = self.buffer.caller == 'px'
|
||||||
|
|
||||||
def getExceptionLine(self, e):
|
def getExceptionLine(self, e):
|
||||||
'''Gets the line describing exception p_e, containing the pathname of
|
'''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
|
'''Write the encountered error into the buffer or raise an exception
|
||||||
if self.raiseErrors is True.'''
|
if self.raiseErrors is True.'''
|
||||||
if self.raiseErrors:
|
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
|
# Add in the error message the line nb where the errors occurs
|
||||||
# within the PX.
|
# within the PX.
|
||||||
locator = self.buffer.env.parser.locator
|
locator = self.buffer.env.parser.locator
|
||||||
|
|
|
@ -121,6 +121,8 @@ class Buffer:
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.subBuffers = {} # ~{i_bufferIndex: Buffer}~
|
self.subBuffers = {} # ~{i_bufferIndex: Buffer}~
|
||||||
self.env = env
|
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):
|
def addSubBuffer(self, subBuffer=None):
|
||||||
if not subBuffer:
|
if not subBuffer:
|
||||||
|
@ -182,7 +184,13 @@ class Buffer:
|
||||||
|
|
||||||
def dumpContent(self, content):
|
def dumpContent(self, content):
|
||||||
'''Dumps string p_content into the buffer.'''
|
'''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):
|
class FileBuffer(Buffer):
|
||||||
|
@ -635,7 +643,7 @@ class MemoryBuffer(Buffer):
|
||||||
if escape: result.dumpContent(res)
|
if escape: result.dumpContent(res)
|
||||||
else: result.write(res)
|
else: result.write(res)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
if self.caller() == 'pod':
|
if self.caller == 'pod':
|
||||||
PodError.dump(result, EVAL_EXPR_ERROR % (
|
PodError.dump(result, EVAL_EXPR_ERROR % (
|
||||||
evalEntry.expr, e), dumpTb=False)
|
evalEntry.expr, e), dumpTb=False)
|
||||||
else: # px
|
else: # px
|
||||||
|
@ -654,9 +662,4 @@ class MemoryBuffer(Buffer):
|
||||||
def clean(self):
|
def clean(self):
|
||||||
'''Cleans the buffer content.'''
|
'''Cleans the buffer content.'''
|
||||||
self.content = u''
|
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):
|
if not HTML_ENTITIES.has_key(k) and not XML_ENTITIES.has_key(k):
|
||||||
HTML_ENTITIES[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
|
'''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):
|
if isinstance(s, unicode):
|
||||||
res = u''
|
res = u''
|
||||||
else:
|
else:
|
||||||
res = ''
|
res = ''
|
||||||
|
odf = format == 'odf'
|
||||||
for c in s:
|
for c in s:
|
||||||
if XML_SPECIAL_CHARS.has_key(c):
|
if XML_SPECIAL_CHARS.has_key(c):
|
||||||
res += XML_SPECIAL_CHARS[c]
|
res += XML_SPECIAL_CHARS[c]
|
||||||
|
elif odf and (c == '\n'):
|
||||||
|
res += '<%s:line-break/>' % nsText
|
||||||
|
elif odf and (c == '\r'):
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
res += c
|
res += c
|
||||||
return res
|
return res
|
||||||
|
|
Loading…
Reference in a new issue