From: <sm...@us...> - 2013-08-04 09:10:03
|
Revision: 7713 http://sourceforge.net/p/docutils/code/7713 Author: smerten Date: 2013-08-04 09:10:00 +0000 (Sun, 04 Aug 2013) Log Message: ----------- ODF headers `text:h` are converted. Error log from XSLT is output so messages become visible. Modified Paths: -------------- trunk/sandbox/odf2docutils/README trunk/sandbox/odf2docutils/global.log trunk/sandbox/odf2docutils/odf2docutils.py trunk/sandbox/odf2docutils/odf2docutilslib/__init__.py trunk/sandbox/odf2docutils/odf2docutilslib/odf2docutils.xsl trunk/sandbox/odf2docutils/tag.log trunk/sandbox/odf2docutils/version.py Modified: trunk/sandbox/odf2docutils/README =================================================================== --- trunk/sandbox/odf2docutils/README 2013-08-03 11:16:24 UTC (rev 7712) +++ trunk/sandbox/odf2docutils/README 2013-08-04 09:10:00 UTC (rev 7713) @@ -81,7 +81,7 @@ .. _Open Document Format: .. _ODF: https://www.oasis-open.org/standards#opendocumentv1.2 -.. _lxml: http://codespeak.net/lxml/ +.. _lxml: http://lxml.de/ .. _filterunit: http://www.merten-home.de/FreeSoftware/filterunit/ Modified: trunk/sandbox/odf2docutils/global.log =================================================================== --- trunk/sandbox/odf2docutils/global.log 2013-08-03 11:16:24 UTC (rev 7712) +++ trunk/sandbox/odf2docutils/global.log 2013-08-04 09:10:00 UTC (rev 7713) @@ -1,4 +1,263 @@ ************************************** +Date: Sun Aug 4 11:05:38 CEST 2013 +Author: stefan +Tag: odf2docutils_1_41 + +-------------------------------------- +Update of /home/stefan/vault/sm/odf2docutils +In directory eskebo:/home/stefan/free/odf2docutils + +Modified Files: + README odf2docutils.py + +-------------------------------------- +Update of /home/stefan/vault/sm/odf2docutils/odf2docutilslib +In directory eskebo:/home/stefan/free/odf2docutils/odf2docutilslib + +Modified Files: + __init__.py + +-------------------------------------- +Log Message: +Error log is output. +************************************** +Date: Sun Aug 4 10:45:04 CEST 2013 +Author: stefan +Tag: odf2docutils_1_40 + +-------------------------------------- +Update of /home/stefan/vault/sm/odf2docutils/odf2docutilslib +In directory eskebo:/home/stefan/free/odf2docutils/odf2docutilslib + +Modified Files: + __init__.py odf2docutils.xsl + +-------------------------------------- +Update of /home/stefan/vault/sm/odf2docutils/tests/textSimple/expected +In directory eskebo:/home/stefan/free/odf2docutils/tests/textSimple/expected + +Modified Files: + manyHeaders.xml + +-------------------------------------- +Update of /home/stefan/vault/sm/odf2docutils/tests/textSimple/input +In directory eskebo:/home/stefan/free/odf2docutils/tests/textSimple/input + +Modified Files: + manyHeaders.odt + +-------------------------------------- +Update of /home/stefan/vault/sm/odf2docutils/tests/textSimple/target +In directory eskebo:/home/stefan/free/odf2docutils/tests/textSimple/target + +Modified Files: + manyHeaders.rst + +-------------------------------------- +Log Message: +Debugging. + +Modified test. +************************************** +Date: Sat Aug 3 19:07:16 CEST 2013 +Author: stefan +Tag: odf2docutils_1_39 + +-------------------------------------- +Update of /home/stefan/vault/sm/odf2docutils/odf2docutilslib +In directory eskebo:/home/stefan/free/odf2docutils/odf2docutilslib + +Modified Files: + odf2docutils.xsl + +-------------------------------------- +Update of /home/stefan/vault/sm/odf2docutils/tests/textSimple/expected +In directory eskebo:/home/stefan/free/odf2docutils/tests/textSimple/expected + +Added Files: + manyHeaders.xml + +-------------------------------------- +Update of /home/stefan/vault/sm/odf2docutils/tests/textSimple/input +In directory eskebo:/home/stefan/free/odf2docutils/tests/textSimple/input + +Added Files: + manyHeaders.odt + +-------------------------------------- +Update of /home/stefan/vault/sm/odf2docutils/tests/textSimple/target +In directory eskebo:/home/stefan/free/odf2docutils/tests/textSimple/target + +Added Files: + manyHeaders.rst + +-------------------------------------- +Log Message: +Added a test exposing a bug. +************************************** +Date: Sat Aug 3 18:32:07 CEST 2013 +Author: stefan +Tag: odf2docutils_1_38 + +-------------------------------------- +Update of /home/stefan/vault/sm/odf2docutils/tests/textSimple/expected +In directory eskebo:/home/stefan/free/odf2docutils/tests/textSimple/expected + +Modified Files: + wrongNestedHeader.xml + +-------------------------------------- +Update of /home/stefan/vault/sm/odf2docutils/tests/textSimple/target +In directory eskebo:/home/stefan/free/odf2docutils/tests/textSimple/target + +Modified Files: + wrongNestedHeader.rst + +-------------------------------------- +Log Message: +Corrected tests. All tests run. +************************************** +Date: Sat Aug 3 18:30:24 CEST 2013 +Author: stefan +Tag: odf2docutils_1_37 + +-------------------------------------- +Update of /home/stefan/vault/sm/odf2docutils/odf2docutilslib +In directory eskebo:/home/stefan/free/odf2docutils/odf2docutilslib + +Modified Files: + odf2docutils.xsl + +-------------------------------------- +Update of /home/stefan/vault/sm/odf2docutils/tests/textSimple/expected +In directory eskebo:/home/stefan/free/odf2docutils/tests/textSimple/expected + +Added Files: + twoHeaders.xml + +-------------------------------------- +Update of /home/stefan/vault/sm/odf2docutils/tests/textSimple/input +In directory eskebo:/home/stefan/free/odf2docutils/tests/textSimple/input + +Added Files: + twoHeaders.odt + +-------------------------------------- +Update of /home/stefan/vault/sm/odf2docutils/tests/textSimple/target +In directory eskebo:/home/stefan/free/odf2docutils/tests/textSimple/target + +Added Files: + twoHeaders.rst + +-------------------------------------- +Log Message: +Corrections. Some tests run. + +Added test. +************************************** +Date: Sat Aug 3 17:42:41 CEST 2013 +Author: stefan +Tag: odf2docutils_1_36 + +-------------------------------------- +Update of /home/stefan/vault/sm/odf2docutils/odf2docutilslib +In directory eskebo:/home/stefan/free/odf2docutils/odf2docutilslib + +Modified Files: + odf2docutils.xsl + +-------------------------------------- +Update of /home/stefan/vault/sm/odf2docutils/tests/textSimple/expected +In directory eskebo:/home/stefan/free/odf2docutils/tests/textSimple/expected + +Added Files: + wrongNestedHeader.xml + +-------------------------------------- +Update of /home/stefan/vault/sm/odf2docutils/tests/textSimple/input +In directory eskebo:/home/stefan/free/odf2docutils/tests/textSimple/input + +Added Files: + wrongNestedHeader.odt + +-------------------------------------- +Update of /home/stefan/vault/sm/odf2docutils/tests/textSimple/target +In directory eskebo:/home/stefan/free/odf2docutils/tests/textSimple/target + +Added Files: + wrongNestedHeader.rst + +-------------------------------------- +Log Message: +Implemented nested headers. Does not work yet. + +Added test with wrongly nested headers. +************************************** +Date: Fri Aug 2 19:16:24 CEST 2013 +Author: stefan +Tag: odf2docutils_1_35 + +-------------------------------------- +Update of /home/stefan/vault/sm/odf2docutils/tests/textSimple/expected +In directory eskebo:/home/stefan/free/odf2docutils/tests/textSimple/expected + +Added Files: + nestedHeader.xml + +-------------------------------------- +Update of /home/stefan/vault/sm/odf2docutils/tests/textSimple/input +In directory eskebo:/home/stefan/free/odf2docutils/tests/textSimple/input + +Added Files: + nestedHeader.odt + +-------------------------------------- +Update of /home/stefan/vault/sm/odf2docutils/tests/textSimple/target +In directory eskebo:/home/stefan/free/odf2docutils/tests/textSimple/target + +Added Files: + nestedHeader.rst + +-------------------------------------- +Log Message: +Added failing test with nested header. +************************************** +Date: Fri Aug 2 19:12:24 CEST 2013 +Author: stefan +Tag: odf2docutils_1_34 + +-------------------------------------- +Update of /home/stefan/vault/sm/odf2docutils/odf2docutilslib +In directory eskebo:/home/stefan/free/odf2docutils/odf2docutilslib + +Modified Files: + odf2docutils.xsl + +-------------------------------------- +Update of /home/stefan/vault/sm/odf2docutils/tests/textSimple/expected +In directory eskebo:/home/stefan/free/odf2docutils/tests/textSimple/expected + +Added Files: + oneHeader.xml + +-------------------------------------- +Update of /home/stefan/vault/sm/odf2docutils/tests/textSimple/input +In directory eskebo:/home/stefan/free/odf2docutils/tests/textSimple/input + +Added Files: + oneHeader.odt + +-------------------------------------- +Update of /home/stefan/vault/sm/odf2docutils/tests/textSimple/target +In directory eskebo:/home/stefan/free/odf2docutils/tests/textSimple/target + +Added Files: + oneHeader.rst + +-------------------------------------- +Log Message: +Added test and implementation converting a single header. +************************************** Date: Fri Aug 2 11:28:13 CEST 2013 Author: stefan Tag: odf2docutils_1_33 Modified: trunk/sandbox/odf2docutils/odf2docutils.py =================================================================== --- trunk/sandbox/odf2docutils/odf2docutils.py 2013-08-03 11:16:24 UTC (rev 7712) +++ trunk/sandbox/odf2docutils/odf2docutils.py 2013-08-04 09:10:00 UTC (rev 7713) @@ -364,6 +364,8 @@ else: outF = None try: - convert(inF, outF, options) + log = convert(inF, outF, options) + if log: + errorOut(log.split('\n')) except Exception, e: errorExit(1, e) Modified: trunk/sandbox/odf2docutils/odf2docutilslib/__init__.py =================================================================== --- trunk/sandbox/odf2docutils/odf2docutilslib/__init__.py 2013-08-03 11:16:24 UTC (rev 7712) +++ trunk/sandbox/odf2docutils/odf2docutilslib/__init__.py 2013-08-04 09:10:00 UTC (rev 7713) @@ -73,6 +73,9 @@ `settings`: ``optparse.Values`` Options from command line. + + return: ``str`` | None + The log created by XSLT or None if the log could not be get. """ # Find XSLT modP = os.path.dirname(__file__) @@ -112,8 +115,10 @@ inXml.close() # Process input + log = None try: result = mainXslt(inDoc) + log = str(mainXslt.error_log) except Exception, e: raise Exception("Error transforming input file %r: %s" % ( inNm, e, )) outS = str(result) @@ -126,3 +131,5 @@ outF.close() else: sys.stdout.write(outS) + + return log Modified: trunk/sandbox/odf2docutils/odf2docutilslib/odf2docutils.xsl =================================================================== --- trunk/sandbox/odf2docutils/odf2docutilslib/odf2docutils.xsl 2013-08-03 11:16:24 UTC (rev 7712) +++ trunk/sandbox/odf2docutils/odf2docutilslib/odf2docutils.xsl 2013-08-04 09:10:00 UTC (rev 7713) @@ -47,9 +47,9 @@ doctype-system="http://docutils.sourceforge.net/docs/ref/docutils.dtd" encoding="utf-8"/> - <!-- Top level of some document --> + <!-- Top level of an ODF document besides text --> <xsl:template - match="office:text|office:drawing|office:presentation|office:spreadsheet"> + match="office:drawing | office:presentation | office:spreadsheet"> <xsl:element name="document" namespace=""> @@ -89,6 +89,211 @@ </xsl:template> <!-- ********************************************************************* --> + <!-- Text --> + + <!-- Section headers in ODF are flat whereas in Docutils titled sections + build a structure. This is somewhat complicated to convert and uses some + modes. + + topHeader + This mode is used for possible top level headers. + --> + + <!-- Top level of an ODF text document. --> + <xsl:template + match="office:text"> + <xsl:element + name="document" + namespace=""> + <!-- All headers in the main document. --> + <xsl:variable + name="allHeaders" + select="text:h"/> + <!-- Generate context containing only the very first document node. --> + <xsl:for-each + select="*[1]"> + <!-- Output content before the first header. --> + <xsl:call-template + name="generateSectionContent"> + <!-- Direct content before the first section ends with the first + header. --> + <xsl:with-param + name="sectionEndId" + select="generate-id($allHeaders[1])"/> + </xsl:call-template> + </xsl:for-each> + <!-- Apply only to the section headers. They care for applying to + their content. --> + <xsl:apply-templates + select="$allHeaders" + mode="topHeader"/> + </xsl:element> + </xsl:template> + + <!-- Section header called directly from top level. These section headers may + have a level > 1 so this needs to be checked. The reason for this is + that headers of higher levels are used for layout purposes sometimes. + --> + <xsl:template + match="text:h" + mode="topHeader"> + <!-- Level of the current header. --> + <xsl:variable + name="level"> + <xsl:call-template + name="outlineLevel"/> + </xsl:variable> + <!-- Nodes which logically embed this header. --> + <xsl:variable + name="embedders" + select="preceding-sibling::text:h[@text:outline-level < $level]"/> + <xsl:if + test="$level = 1 or not($embedders)"> + <xsl:apply-templates + select="."/> + </xsl:if> + <!-- If there are embedders do nothing because this node will be called by + its embedder. --> + </xsl:template> + + <!-- Convert a header. --> + <xsl:template + match="text:h"> + <!-- Level of the current header. --> + <xsl:variable + name="level"> + <xsl:call-template + name="outlineLevel"/> + </xsl:variable> + <!-- Enders of this section are all following headers with same or lower + level. --> + <xsl:variable + name="enders" + select="following-sibling::text:h[not(@text:outline-level) or @text:outline-level <= $level]"/> + <!-- Emebdees are all following headers with higher level. --> + <xsl:variable + name="embeddees" + select="following-sibling::text:h[@text:outline-level > $level]"/> + <xsl:element + name="section" + namespace=""> + <xsl:element + name="title" + namespace=""> + <xsl:value-of + select="."/> + </xsl:element> + <!-- Generate context containing the next node. --> + <xsl:for-each + select="following-sibling::*[1]"> + <xsl:call-template + name="generateSectionContent"> + <xsl:with-param + name="firstSubsectionId" + select="generate-id($embeddees[1])"/> + <xsl:with-param + name="sectionEndId" + select="generate-id($enders[1])"/> + <xsl:with-param + name="level" + select="$level"/> + </xsl:call-template> + </xsl:for-each> + </xsl:element> + </xsl:template> + + <!-- Output section content. Current node is first node of remaining section + content. --> + <xsl:template + name="generateSectionContent"> + <!-- Id of first subsection node after the direct section content or empty + string for no subsection. Node may be after the one with + `sectionEndId` in which case it is synonymous to an empty string. --> + <xsl:param + name="firstSubsectionId" + select="''"/> + <!-- Id of first node after the section or empty string for end of + document. --> + <xsl:param + name="sectionEndId" + select="''"/> + <!-- Level of the section. --> + <xsl:param + name="level" + select="0"/> + <!-- All elements in section and after it. --> + <xsl:variable + name="allNodes" + select=". | following-sibling::*"/> + <xsl:variable + name="sectionEndPosition"> + <xsl:call-template + name="id2Position"> + <xsl:with-param + name="contextNodes" + select="$allNodes"/> + <xsl:with-param + name="id" + select="$sectionEndId"/> + </xsl:call-template> + </xsl:variable> + <!-- Position of first subsection in all nodes. --> + <xsl:variable + name="firstSubsectionPositionAll"> + <xsl:call-template + name="id2Position"> + <xsl:with-param + name="contextNodes" + select="$allNodes"/> + <xsl:with-param + name="id" + select="$firstSubsectionId"/> + <xsl:with-param + name="isEndDefault" + select="false()"/> + </xsl:call-template> + </xsl:variable> + <!-- Position of first subsection or <= 0 when no subsection exists. --> + <xsl:variable + name="firstSubsectionPosition"> + <xsl:choose> + <xsl:when + test="$firstSubsectionPositionAll <= $sectionEndPosition"> + <xsl:value-of + select="$firstSubsectionPositionAll"/> + </xsl:when> + <xsl:otherwise> + <xsl:value-of + select="0"/> + </xsl:otherwise> + </xsl:choose> + </xsl:variable> + <!-- The position of the first node after the content. --> + <xsl:variable + name="contentEndPosition"> + <xsl:choose> + <xsl:when + test="$firstSubsectionPosition > 0"> + <!-- Subsection exists - direct content reaches until there. --> + <xsl:value-of + select="$firstSubsectionPosition"/> + </xsl:when> + <xsl:otherwise> + <!-- No subsection - direct content reaches until end. --> + <xsl:value-of + select="$sectionEndPosition"/> + </xsl:otherwise> + </xsl:choose> + </xsl:variable> + <!-- Output direct content. --> + <xsl:apply-templates + select="$allNodes[position() < $contentEndPosition]"/> + <!-- Output subsections by applying to all headers of subsections. --> + <xsl:apply-templates + select="$allNodes[position() < $sectionEndPosition and name() = 'text:h' and @text:outline-level = $level + 1]"/> + </xsl:template> + + <!-- ********************************************************************* --> <!-- Lists --> <!-- Powerpoint slides employ a wrong nesting. It closes a nested list and @@ -126,7 +331,7 @@ name="list_item" namespace=""> <xsl:apply-templates - select="text:p|text:list"/> + select="text:p | text:list"/> </xsl:element> </xsl:template> @@ -153,4 +358,80 @@ match="text()"> </xsl:template> + <!--**********************************************************************--> + <!-- Common functions --> + + <!-- Compute the outline level of the current node considering defaults. --> + <xsl:template + name="outlineLevel"> + <xsl:choose> + <xsl:when + test="@text:outline-level"> + <xsl:value-of + select="@text:outline-level"/> + </xsl:when> + <xsl:otherwise> + <!-- Outline level defaults to 1 according to ODF specification. --> + <xsl:value-of + select="1"/> + </xsl:otherwise> + </xsl:choose> + </xsl:template> + + <!-- Returns the position of a node in a given context. Returns -1 if + node is not contained in context. --> + <xsl:template + name="id2Position"> + <!-- Context in which the position is to be determined. --> + <xsl:param + name="contextNodes"/> + <!-- Id of the node to get the position of. Must be created by + `generate-id()`. --> + <xsl:param + name="id"/> + <!-- If `id` is empty the first position after the context is returned + if this is true. Otherwise 0 will be returned. --> + <xsl:param + name="isEndDefault" + select="true()"/> + <xsl:choose> + <xsl:when + test="$id != ''"> + <xsl:variable + name="position"> + <xsl:for-each + select="$contextNodes"> + <xsl:if + test="generate-id(.) = $id"> + <!-- Node found - return its position. --> + <xsl:value-of + select="position()"/> + </xsl:if> + </xsl:for-each> + </xsl:variable> + <xsl:choose> + <xsl:when + test="$position != ''"> + <xsl:value-of + select="$position"/> + </xsl:when> + <xsl:otherwise> + <!-- Node not found. --> + <xsl:value-of + select="-1"/> + </xsl:otherwise> + </xsl:choose> + </xsl:when> + <xsl:when + test="$isEndDefault"> + <xsl:value-of + select="count($contextNodes) + 1"/> + </xsl:when> + <xsl:otherwise> + <xsl:value-of + select="0"/> + </xsl:otherwise> + </xsl:choose> + </xsl:template> + </xsl:stylesheet> Modified: trunk/sandbox/odf2docutils/tag.log =================================================================== --- trunk/sandbox/odf2docutils/tag.log 2013-08-03 11:16:24 UTC (rev 7712) +++ trunk/sandbox/odf2docutils/tag.log 2013-08-04 09:10:00 UTC (rev 7713) @@ -1 +1 @@ -odf2docutils_1_33 +odf2docutils_1_41 Modified: trunk/sandbox/odf2docutils/version.py =================================================================== --- trunk/sandbox/odf2docutils/version.py 2013-08-03 11:16:24 UTC (rev 7712) +++ trunk/sandbox/odf2docutils/version.py 2013-08-04 09:10:00 UTC (rev 7713) @@ -1 +1 @@ -version = '0.2.1' +version = '0.3.0' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |