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:
		
							parent
							
								
									66a02c453e
								
							
						
					
					
						commit
						4fe5c5e164
					
				
					 5 changed files with 1754 additions and 1736 deletions
				
			
		|  | @ -28,7 +28,7 @@ class ToolWrapper(AbstractWrapper): | ||||||
|                 return NO_PYTHON % value |                 return NO_PYTHON % value | ||||||
|             if os.system('%s -c "import uno"' % value): |             if os.system('%s -c "import uno"' % value): | ||||||
|                 return NOT_UNO_ENABLED_PYTHON % value |                 return NOT_UNO_ENABLED_PYTHON % value | ||||||
|         return None |         return True | ||||||
| 
 | 
 | ||||||
|     podOutputFormats = ('odt', 'pdf', 'doc', 'rtf') |     podOutputFormats = ('odt', 'pdf', 'doc', 'rtf') | ||||||
|     def getPodOutputFormats(self): |     def getPodOutputFormats(self): | ||||||
|  |  | ||||||
|  | @ -213,6 +213,7 @@ class Renderer: | ||||||
|            p_odtFile (content.xml or styles.xml). p_context is given by the pod |            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.''' |            user, while p_inserts depends on the ODT file we must parse.''' | ||||||
|         evalContext = {'xhtml': self.renderXhtml, |         evalContext = {'xhtml': self.renderXhtml, | ||||||
|  |                        'text':  self.renderText, | ||||||
|                        'test': self.evalIfExpression, |                        'test': self.evalIfExpression, | ||||||
|                        'document': self.importDocument} # Default context |                        'document': self.importDocument} # Default context | ||||||
|         if hasattr(context, '__dict__'): |         if hasattr(context, '__dict__'): | ||||||
|  | @ -232,12 +233,18 @@ class Renderer: | ||||||
|            of ODT content.''' |            of ODT content.''' | ||||||
|         stylesMapping = self.stylesManager.checkStylesMapping(stylesMapping) |         stylesMapping = self.stylesManager.checkStylesMapping(stylesMapping) | ||||||
|         ns = self.currentParser.env.namespaces |         ns = self.currentParser.env.namespaces | ||||||
|         # xhtmlString is only a chunk of XHTML. So we must surround it a tag in |         # xhtmlString can only be a chunk of XHTML. So we must surround it a | ||||||
|         # order to get a XML-compliant file (we need a root tag). |         # tag in order to get a XML-compliant file (we need a root tag). | ||||||
|         xhtmlContent = '<p>%s</p>' % xhtmlString |         xhtmlContent = '<p>%s</p>' % xhtmlString | ||||||
|         return Xhtml2OdtConverter(xhtmlContent, encoding, self.stylesManager, |         return Xhtml2OdtConverter(xhtmlContent, encoding, self.stylesManager, | ||||||
|                                   stylesMapping, ns).run() |                                   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): |     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 | ||||||
|            default pod context. It represents an 'if' expression (as opposed to |            default pod context. It represents an 'if' expression (as opposed to | ||||||
|  |  | ||||||
							
								
								
									
										3435
									
								
								pod/test/Tests.rtf
									
										
									
									
									
								
							
							
						
						
									
										3435
									
								
								pod/test/Tests.rtf
									
										
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							|  | @ -126,10 +126,6 @@ class HtmlElement: | ||||||
|                 (parentElem.tagsToClose[-1].elemType == 'para') and \ |                 (parentElem.tagsToClose[-1].elemType == 'para') and \ | ||||||
|                 (self.elem in NOT_INSIDE_P): |                 (self.elem in NOT_INSIDE_P): | ||||||
|                 return (parentElem.tagsToClose[-1].setConflictual(),) |                 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 |             # Check elements that can't be found within a list | ||||||
|             if (parentElem.elemType=='list') and (self.elem in NOT_INSIDE_LIST): |             if (parentElem.elemType=='list') and (self.elem in NOT_INSIDE_LIST): | ||||||
|                 return (parentElem.setConflictual(),) |                 return (parentElem.setConflictual(),) | ||||||
|  | @ -154,7 +150,7 @@ class HtmlElement: | ||||||
|             self.tagsToClose.append(HtmlElement('p',{})) |             self.tagsToClose.append(HtmlElement('p',{})) | ||||||
| 
 | 
 | ||||||
|     def dump(self, start, env): |     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.''' |            element. We must take care of potential innerTags.''' | ||||||
|         # Compute the tag in itself |         # Compute the tag in itself | ||||||
|         tag = '' |         tag = '' | ||||||
|  | @ -171,6 +167,8 @@ class HtmlElement: | ||||||
|                     # I have interrupted a numbered list. I need to continue |                     # I have interrupted a numbered list. I need to continue | ||||||
|                     # the numbering. |                     # the numbering. | ||||||
|                     attrs += ' %s:continue-numbering="true"' % env.textNs |                     attrs += ' %s:continue-numbering="true"' % env.textNs | ||||||
|  |             else: | ||||||
|  |                 attrs = env.getOdtAttributes(self) | ||||||
|         tag = prefix + self.getOdfTag(env) + attrs + '>' |         tag = prefix + self.getOdfTag(env) + attrs + '>' | ||||||
|         # Close/open subTags if any |         # Close/open subTags if any | ||||||
|         for subElem in self.tagsToClose: |         for subElem in self.tagsToClose: | ||||||
|  | @ -274,21 +272,29 @@ class XhtmlEnvironment(XmlEnvironment): | ||||||
|                     self.dumpString(c) |                     self.dumpString(c) | ||||||
|             self.currentContent = u'' |             self.currentContent = u'' | ||||||
| 
 | 
 | ||||||
|     def dumpStyledElement(self, elem, odfTag, attrs): |     def getOdtAttributes(self, htmlElem, htmlAttrs={}): | ||||||
|         '''Dumps an element that potentially has associated style |         '''Gets the ODT attributes to dump for p_currentElem. p_htmlAttrs are | ||||||
|            information.''' |            the parsed attributes from the XHTML p_currentElem.''' | ||||||
|         self.dumpString('<' + odfTag) |         odtStyle = self.parser.caller.findStyle(htmlElem.elem, htmlAttrs) | ||||||
|         odtStyle = self.parser.caller.findStyle(elem, attrs) |  | ||||||
|         styleName = None |         styleName = None | ||||||
|         if odtStyle: |         if odtStyle: | ||||||
|             styleName = odtStyle.name |             styleName = odtStyle.name | ||||||
|         elif DEFAULT_ODT_STYLES.has_key(elem): |         elif DEFAULT_ODT_STYLES.has_key(htmlElem.elem): | ||||||
|             styleName = DEFAULT_ODT_STYLES[elem] |             styleName = DEFAULT_ODT_STYLES[htmlElem.elem] | ||||||
|  |         res = '' | ||||||
|         if styleName: |         if styleName: | ||||||
|             self.dumpString(' %s:style-name="%s"' % (self.textNs, styleName)) |             res += ' %s:style-name="%s"' % (self.textNs, styleName) | ||||||
|             if (elem in XHTML_HEADINGS) and (odtStyle.outlineLevel != None): |             if (htmlElem.elem in XHTML_HEADINGS) and \ | ||||||
|                 self.dumpString(' %s:outline-level="%d"' % ( |                (odtStyle.outlineLevel != None): | ||||||
|                     self.textNs, odtStyle.outlineLevel)) |                 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('>') |         self.dumpString('>') | ||||||
| 
 | 
 | ||||||
|     def getTags(self, elems, start=True): |     def getTags(self, elems, start=True): | ||||||
|  | @ -417,7 +423,7 @@ class XhtmlParser(XmlParser): | ||||||
|         odfTag = currentElem.getOdfTag(e) |         odfTag = currentElem.getOdfTag(e) | ||||||
| 
 | 
 | ||||||
|         if HTML_2_ODT.has_key(elem): |         if HTML_2_ODT.has_key(elem): | ||||||
|             e.dumpStyledElement(elem, odfTag, attrs) |             e.dumpStyledElement(currentElem, odfTag, attrs) | ||||||
|         elif elem == 'a': |         elif elem == 'a': | ||||||
|             e.dumpString('<%s %s:type="simple"' % (odfTag, e.linkNs)) |             e.dumpString('<%s %s:type="simple"' % (odfTag, e.linkNs)) | ||||||
|             if attrs.has_key('href'): |             if attrs.has_key('href'): | ||||||
|  |  | ||||||
|  | @ -33,7 +33,7 @@ class FolderDeleter: | ||||||
|     delete = staticmethod(delete) |     delete = staticmethod(delete) | ||||||
| 
 | 
 | ||||||
| # ------------------------------------------------------------------------------ | # ------------------------------------------------------------------------------ | ||||||
| extsToClean = ('.pyc', '.pyo') | extsToClean = ('.pyc', '.pyo', '.fsz', '.deltafsz', '.dat', '.log') | ||||||
| def cleanFolder(folder, exts=extsToClean, verbose=False): | def cleanFolder(folder, exts=extsToClean, verbose=False): | ||||||
|     '''This function allows to remove, in p_folder and subfolders, any file |     '''This function allows to remove, in p_folder and subfolders, any file | ||||||
|        whose extension is in p_exts.''' |        whose extension is in p_exts.''' | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Gaetan Delannay
						Gaetan Delannay