FB2: fix verse handling in lyrics.
authorMichał Górny <mgorny@gentoo.org>
Wed, 29 Aug 2012 21:02:51 +0000 (23:02 +0200)
committerMichał Górny <mgorny@gentoo.org>
Wed, 29 Aug 2012 21:02:51 +0000 (23:02 +0200)
Use the epub verse conversion code to convert verses to a more suitable
XML format.

librarian/fb2.py
librarian/fb2/poems.xslt

index b0ad410..78707a9 100644 (file)
@@ -8,6 +8,7 @@ from copy import deepcopy
 from lxml import etree
 
 from librarian import functions, OutputFile
 from lxml import etree
 
 from librarian import functions, OutputFile
+from .epub import replace_by_verse
 
 
 functions.reg_substitute_entities()
 
 
 functions.reg_substitute_entities()
@@ -30,6 +31,10 @@ def transform(wldoc, verbose=False,
     style_filename = os.path.join(os.path.dirname(__file__), 'fb2/fb2.xslt')
     style = etree.parse(style_filename)
 
     style_filename = os.path.join(os.path.dirname(__file__), 'fb2/fb2.xslt')
     style = etree.parse(style_filename)
 
+    replace_by_verse(document.edoc)
+
     result = document.transform(style)
 
     return OutputFile.from_string(unicode(result).encode('utf-8'))
     result = document.transform(style)
 
     return OutputFile.from_string(unicode(result).encode('utf-8'))
+
+# vim:et
index d276ebf..bbc9407 100644 (file)
        <!-- regular poem elements -->
        <xsl:template mode="para" match="strofa">
                <stanza>
        <!-- regular poem elements -->
        <xsl:template mode="para" match="strofa">
                <stanza>
-                       <xsl:call-template name="split-poem">
-                               <xsl:with-param name="list" select="."/>
-                       </xsl:call-template>
+                       <xsl:apply-templates mode="poem"/>
                </stanza>
        </xsl:template>
 
                </stanza>
        </xsl:template>
 
-       <!-- split into verses -->
-       <xsl:template name="split-poem">
-               <xsl:param name="list"></xsl:param>
+       <!-- XXX: it should be done elsewhere but our cheap verse splitting
+               puts it here -->
+       <xsl:template match="motyw" mode="poem"/>
 
 
-               <xsl:if test="$list != ''">
-                       <xsl:variable name="before"
-                               select="substring-before(concat($list, '/'), '/')"/>
-                       <xsl:variable name="after"
-                               select="substring-after($list, '/')"/>
-
-                       <v>
-                               <xsl:value-of select="$before"/>
-                       </v>
-
-                       <xsl:call-template name="split-poem">
-                               <xsl:with-param name="list" select="$after"/>
-                       </xsl:call-template>
-               </xsl:if>
+       <xsl:template mode="poem" match="wers_normalny">
+               <v><xsl:apply-templates mode="inline"/></v>
        </xsl:template>
 </xsl:stylesheet>
        </xsl:template>
 </xsl:stylesheet>