1
XHTML to ODT XML transformation
2
===============================
3
4
These stylesheets convert namespaced XHTML to ODT_.
5
6
You can download_ them from the project's website_.
7
8
The HTML must be well-formed and valid, so I recommand running it through Tidy_
9
before sending it to the stylesheets.
10
11
Those stylesheets do not build a whole ODT file, they only convert the XHTML to
12
the equivalent OpenDocument XML. The result can then be inserted in a template
13
ODT file. The HTML may be included in an ODT document, the ODT will be left
14
untouched.
15
16
.. _website: http://xhtml2odt.org/
17
.. _download: http://xhtml2odt.org/dl/
18
.. _ODT: http://en.wikipedia.org/wiki/OpenDocument
19
.. _Tidy: http://tidy.sourceforge.net/
20
21
22
Caveats
23
-------
24
25
Styles:
26
    Some default styles will be added to the document, but not on the first
27
    pass. After converting to ODT, you must run the ``content.xml`` and the
28
    ``styles.xml`` files (in the ODT file) through the ``xsl/styles.xsl``
29
    stylesheet to add the styles. When the default styles are added, the
30
    stylesheet checks that the style is not already present, so customizations
31
    to the template ODT file will be preserved. It will however add styles that
32
    are not used in the text, but that's harmless.
33
34
Images:
35
    Images are not added, you must manually go trough the ``draw:image``
36
    elements in the converted ODT text and use the ``xlink:href`` attribute to
37
    download or copy the image. While you're at it, you should update the image
38
    dimensions if the were not provided in the ``img`` tag.
39
40
41
Command-line scripts
42
--------------------
43
44
Three command-line scripts to run the stylesheets are provided, one is
45
Python-based, the other is PHP-based, the last one is shell-based. The first
46
two do import the styles and the images, so they can also be used as a code
47
example for these two steps in other languages and actual export plugins. The
48
shell script is more of a minimalist approach to demonstrate the simplest
49
possible use of the stylesheets.
50
51
Documentation for the PHP and Python scripts can be generated using the ``make
52
doc`` command. This will require Sphinx_ for Python and phpDocumentor_ for PHP.
53
54
.. _sphinx: http://sphinx.pocoo.org/
55
.. _phpDocumentor: http://www.phpdoc.org/
56
57
The python script
58
^^^^^^^^^^^^^^^^^
59
60
The python script is the preferred command-line script, because it currently is
61
a little more complete than the PHP script. It depends on the following Python
62
modules:
63
64
* uTidylib_
65
* lxml_
66
* PIL_
67
68
To get information on the script's options, run it with ``--help``::
69
70
    ./xhtml2odt.py --help
71
72
The script can be installed on the system with the ``make install`` command.
73
74
.. _uTidylib: http://pypi.python.org/pypi/uTidylib
75
.. _lxml: http://pypi.python.org/pypi/lxml
76
.. _PIL: http://pypi.python.org/pypi/PIL
77
78
The PHP script
79
^^^^^^^^^^^^^^
80
81
The PHP script can be used as an example to create an ODT export plugin for a
82
PHP-based application. It contains comments on what you should do differently
83
in a web-based application. If you want a real PHP-based export plugin, you can
84
look at the code of the `Dotclear ODT export plugin`_.
85
86
The PHP script requires the zip_ module, and will work better with the `tidy
87
extension`_.
88
89
To get information on the script's options, run it with ``--help``::
90
91
    ./xhtml2odt.php --help
92
93
.. _Dotclear ODT export plugin: http://lab.dotclear.org/wiki/plugin/odt
94
.. _zip: http://php.net/manual/en/zip.installation.php
95
.. _tidy extension: http://php.net/manual/en/book.tidy.php
96
97
98
Tests
99
-----
100
101
The unit tests are python-based, you need to install the nose_ python module
102
availble from PyPI (or your distribution).
103
104
Then, just run ``nosetests tests``.
105
106
.. _nose: http://pypi.python.org/pypi/nose/
107
108
109
References
110
----------
111
112
* `ODT export for Dotclear <http://lab.dotclear.org/wiki/plugin/odt>`_
113
* `ODT export for Trac <http://trac-hacks.org/wiki/OdtExportPlugin>`_
114
* `ODT export for Dokuwiki <http://www.dokuwiki.org/plugin:odt>`_
115
  (not using this project, but similar and by the same author)
116
117
118
License
119
-------
120
121
Copyright (C) 2009-2010 `Aurelien Bompard`_.
122
123
Inspired by the work on docbook2odt_, by Roman Fordinal. Many thanks to him.
124
125
.. _Aurelien Bompard: http://aurelien.bompard.org/
126
.. _docbook2odt: http://open.comsultia.com/docbook2odf/
127
128
License is LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl-2.1.html
129
130
This library is free software; you can redistribute it and/or
131
modify it under the terms of the GNU Lesser General Public
132
License as published by the Free Software Foundation; either
133
version 2.1 of the License, or (at your option) any later version.
134
135
This library is distributed in the hope that it will be useful,
136
but WITHOUT ANY WARRANTY; without even the implied warranty of
137
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
138
Lesser General Public License for more details.
139
140
You should have received a copy of the GNU Lesser General Public
141
License along with this library; if not, write to the Free Software
142
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
143
144
.. vim:syntax=rst