appy.gen: bugfix in the validator for the default field 'UNO-enabled Python interpreter'; appy.pod: added default function 'text' that allows to dump a string containing carriage returns into the ODT, with statements like 'do... from text(someString)'; appy.pod: bugfix in the management of conflictual inner-tags in the odt2html conversion: in some cases (when style mappings are applied), empty tags that needed to be removed were not removed because of the presence of tag attributes.

This commit is contained in:
Gaetan Delannay 2011-03-18 16:52:15 +01:00
parent 66a02c453e
commit 4fe5c5e164
5 changed files with 1754 additions and 1736 deletions

View file

@ -28,7 +28,7 @@ class ToolWrapper(AbstractWrapper):
return NO_PYTHON % value
if os.system('%s -c "import uno"' % value):
return NOT_UNO_ENABLED_PYTHON % value
return None
return True
podOutputFormats = ('odt', 'pdf', 'doc', 'rtf')
def getPodOutputFormats(self):

View file

@ -213,6 +213,7 @@ class Renderer:
p_odtFile (content.xml or styles.xml). p_context is given by the pod
user, while p_inserts depends on the ODT file we must parse.'''
evalContext = {'xhtml': self.renderXhtml,
'text': self.renderText,
'test': self.evalIfExpression,
'document': self.importDocument} # Default context
if hasattr(context, '__dict__'):
@ -232,12 +233,18 @@ class Renderer:
of ODT content.'''
stylesMapping = self.stylesManager.checkStylesMapping(stylesMapping)
ns = self.currentParser.env.namespaces
# xhtmlString is only a chunk of XHTML. So we must surround it a tag in
# order to get a XML-compliant file (we need a root tag).
# xhtmlString can only be a chunk of XHTML. So we must surround it a
# tag in order to get a XML-compliant file (we need a root tag).
xhtmlContent = '<p>%s</p>' % xhtmlString
return Xhtml2OdtConverter(xhtmlContent, encoding, self.stylesManager,
stylesMapping, ns).run()
def renderText(self, text, encoding='utf-8'):
'''Method that can be used (under the name 'text') into a pod template
for inserting a text containing carriage returns.'''
text = text.replace('\r\n', '<br/>').replace('\n', '<br/>')
return self.renderXhtml(text, encoding)
def evalIfExpression(self, condition, ifTrue, ifFalse):
'''This method implements the method 'test' which is proposed in the
default pod context. It represents an 'if' expression (as opposed to

File diff suppressed because it is too large Load diff

View file

@ -126,10 +126,6 @@ class HtmlElement:
(parentElem.tagsToClose[-1].elemType == 'para') and \
(self.elem in NOT_INSIDE_P):
return (parentElem.tagsToClose[-1].setConflictual(),)
#if (parentElem.elem in OUTER_TAGS) and parentElem.tagsToClose and \
# (parentElem.tagsToClose[-1].elem == 'p') and \
# (self.elem in NOT_INSIDE_P):
# return (parentElem.tagsToClose[-1].setConflictual(),)
# Check elements that can't be found within a list
if (parentElem.elemType=='list') and (self.elem in NOT_INSIDE_LIST):
return (parentElem.setConflictual(),)
@ -154,7 +150,7 @@ class HtmlElement:
self.tagsToClose.append(HtmlElement('p',{}))
def dump(self, start, env):
'''Dumps the start or stop (depending on p_start) tag of this HTML
'''Dumps the start or end (depending on p_start) tag of this HTML
element. We must take care of potential innerTags.'''
# Compute the tag in itself
tag = ''
@ -171,6 +167,8 @@ class HtmlElement:
# I have interrupted a numbered list. I need to continue
# the numbering.
attrs += ' %s:continue-numbering="true"' % env.textNs
else:
attrs = env.getOdtAttributes(self)
tag = prefix + self.getOdfTag(env) + attrs + '>'
# Close/open subTags if any
for subElem in self.tagsToClose:
@ -274,21 +272,29 @@ class XhtmlEnvironment(XmlEnvironment):
self.dumpString(c)
self.currentContent = u''
def dumpStyledElement(self, elem, odfTag, attrs):
'''Dumps an element that potentially has associated style
information.'''
self.dumpString('<' + odfTag)
odtStyle = self.parser.caller.findStyle(elem, attrs)
def getOdtAttributes(self, htmlElem, htmlAttrs={}):
'''Gets the ODT attributes to dump for p_currentElem. p_htmlAttrs are
the parsed attributes from the XHTML p_currentElem.'''
odtStyle = self.parser.caller.findStyle(htmlElem.elem, htmlAttrs)
styleName = None
if odtStyle:
styleName = odtStyle.name
elif DEFAULT_ODT_STYLES.has_key(elem):
styleName = DEFAULT_ODT_STYLES[elem]
elif DEFAULT_ODT_STYLES.has_key(htmlElem.elem):
styleName = DEFAULT_ODT_STYLES[htmlElem.elem]
res = ''
if styleName:
self.dumpString(' %s:style-name="%s"' % (self.textNs, styleName))
if (elem in XHTML_HEADINGS) and (odtStyle.outlineLevel != None):
self.dumpString(' %s:outline-level="%d"' % (
self.textNs, odtStyle.outlineLevel))
res += ' %s:style-name="%s"' % (self.textNs, styleName)
if (htmlElem.elem in XHTML_HEADINGS) and \
(odtStyle.outlineLevel != None):
res += ' %s:outline-level="%d"' % (self.textNs, \
odtStyle.outlineLevel)
return res
def dumpStyledElement(self, htmlElem, odfTag, attrs):
'''Dumps an element that potentially has associated style
information.'''
self.dumpString('<' + odfTag)
self.dumpString(self.getOdtAttributes(htmlElem, attrs))
self.dumpString('>')
def getTags(self, elems, start=True):
@ -417,7 +423,7 @@ class XhtmlParser(XmlParser):
odfTag = currentElem.getOdfTag(e)
if HTML_2_ODT.has_key(elem):
e.dumpStyledElement(elem, odfTag, attrs)
e.dumpStyledElement(currentElem, odfTag, attrs)
elif elem == 'a':
e.dumpString('<%s %s:type="simple"' % (odfTag, e.linkNs))
if attrs.has_key('href'):

View file

@ -33,7 +33,7 @@ class FolderDeleter:
delete = staticmethod(delete)
# ------------------------------------------------------------------------------
extsToClean = ('.pyc', '.pyo')
extsToClean = ('.pyc', '.pyo', '.fsz', '.deltafsz', '.dat', '.log')
def cleanFolder(folder, exts=extsToClean, verbose=False):
'''This function allows to remove, in p_folder and subfolders, any file
whose extension is in p_exts.'''