20120310
========
Started new module :mod:`lino.utils.xmlgen.odf`.
A bug in appy.pod
-----------------
Oh je: appy.pod hat scheinbar noch einen Bug in der Konvertierung von xhtml nach ODF.
Hier das XHTML-Fragment, das ich ihm schicke::
"Mesilash\xe4\xe4likud" on s, \u0161, z ja \u017e.
Nad on eesti keeles ka olemas, aga nende erinevus
ei ole meil v\xe4ga t\xe4htis. Prantslastele aga k\xfcll.
terav |
pehme |
supp |
zoom |
\u0161okk |
\u017eurnaal, \u017eanre |
Aus heiterem Himmel vergisst er (hinter dem Wort "terav") einen ```` zu schließen::
"Mesilashäälikud" on s, š, z ja ž.
Nad on eesti keeles ka olemas, aga nende erinevus
ei ole meil väga tähtis. Prantslastele aga küll.teravpehmesuppzoomšokkžurnaal, žanrela soupe[sup]supple garage[ga'raaž]garaažle genre[žA~rə]žanrele journal[žur'nal](1) päevik; (2) ajalehtle choc[žok](1) šokk; (2) löök
Und wenn ich nun restify() mit odtwriter statt htmlwriter aufriefe?
Linos neue Funktion :func:`lino.utils.restify.rst2odt` tut ungefähr
das Gleiche wie Dave Kuhlmans Skript, aber wird im gleichen
Python-Prozess aufgerufen.
Und weil ich nur einen kleinen Teil eines .odt-Dokuments will,
subclasse ich seinen Writer.
Geht fein... aber er verwendet ja natürlich andere Style mappings als
`appy.pod`.
Ich merke schon, dass mein :mod:`lino.utils.xmlgen.odf` vielleicht Unsinn ist.
Und ich habe keine Ahnung, wodurch der Bug ausgelöst wurde
(also wie ich ihn umgehen kann).
Dabei würde ich doch so gern für Donnerstag
meinen Französischkurs auch ausdrucken...
Mit der `Web-Version `_
fange ich an, einigermaßen zufrieden zu sein.
Aber für die Schüler müsste ich eine Verson auf Papier machen.
xhtml2odt
---------
The bug described in the previous section made me discover http://xhtml2odt.org/.
`xhtml2odt `_, like :term:`appy.pod`, generates .odt files.
But unlike :term:`appy.pod` it uses XSL translation to convert xhtml to odt.
I played around and got some results (see :srcref:`/lino/modlib/vocbook/base.py`).
My idea was to feed the content.xml as a template through Cheetah in order to
replace variable content.
The following error caused me some headache::
Error while evaluating the expression "self.as_odt()" defined in the "from" part of a statement.
File "", line 1, in
File "t:\hgwork\lino\lino\modlib\vocbook\base.py", line 614, in as_odt
xhtml = odtfile.xhtml_to_odt(xhtml)
File "l:\snapshots\xhtml2odt-1.3\xhtml2odt.py", line 291, in xhtml_to_odt
odt = transform(xhtml, **params)
File "xslt.pxi", line 568, in lxml.etree.XSLT.__call__ (src/lxml/lxml.etree.c:120289)
: xsl:comment : '--' or ending '-' not allowed in comment
It comes when there is an unknown tag in my source (and when verbose is True).
It is caused by the following rule in `xhtml2odt.xsl`::
Unknown tag :
When the case happens, I temporarily replace the
```` by ```` so I can at least see the reason.
Couldn't decide whether or not this is a bug in xhtml2odt...
Anyway I stopped this direction again
(`USE_XHTML2ODT = False` in the source code)
because I discovered a workaround for the urgent appy.pod problem,
and because I understood that my idea might not be trivial to finish.
appy.pod seems more suited for my use case, also concerning management of styles.
Still I have a feeling that Aurélien's approach of using XSLT is more "healthy"
than Gaëtan's self-written parser. Is it possible to combine both?