1 # Copyright (C) 2013 Stefan Merten
3 # This file is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published
5 # by the Free Software Foundation; either version 2 of the License,
6 # or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 Do conversion by using Python.
22 __docformat__
= 'reStructuredText' # Formatted to be rendered by epydoc
24 ###############################################################################
25 ###############################################################################
30 from docutils_xml
.parsers
.xml
import XmlParser
, XmlVisitor
, SomeChildren
, Uri2Prefixes
32 ###############################################################################
33 ###############################################################################
36 ###############################################################################
37 ###############################################################################
40 ###############################################################################
41 ###############################################################################
44 ###############################################################################
45 ###############################################################################
48 class OdfVisitor(XmlVisitor
):
50 Visitor class for visiting an ODF element tree.
53 ###########################################################################
56 def visit_draw_page(self
, elem
):
57 self
.push(docutils
.nodes
.section())
59 def depart_draw_page(self
, elem
):
62 ###########################################################################
65 def visit_text_list(self
, elem
):
66 self
.push(docutils
.nodes
.bullet_list(bullet
="*"))
67 raise SomeChildren(( ( "text", "list-item" ), ))
69 def depart_text_list(self
, elem
):
72 def visit_text_listitem(self
, elem
):
73 self
.push(docutils
.nodes
.list_item())
74 raise SomeChildren(( ( "text", "list" ), ( "text", "p" ), ))
76 def depart_text_listitem(self
, elem
):
79 ###########################################################################
82 def visit_text_p(self
, elem
):
83 para
= docutils
.nodes
.paragraph()
84 if elem
.text
is not None:
85 para
.append(docutils
.nodes
.Text(elem
.text
))
87 # TODO tails of embedded inline elements must be considered
89 def depart_text_p(self
, elem
):
94 ###############################################################################
96 class Parser(XmlParser
):
98 Parse the input file and translate it to the output file by Python.
101 uri2Prefixes
= Uri2Prefixes((
102 ( "http://www.w3.org/2001/xml-events", 'dom' ),
103 ( "urn:oasis:names:tc:opendocument:xmlns:drawing:1.0", 'draw' ),
104 ( "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0", 'fo' ),
105 ( "urn:oasis:names:tc:opendocument:xmlns:presentation:1.0", 'presentation' ),
106 ( "urn:oasis:names:tc:opendocument:xmlns:script:1.0", 'script' ),
107 ( "urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0", 'smil' ),
108 ( "urn:oasis:names:tc:opendocument:xmlns:style:1.0", 'style' ),
109 ( "urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0", 'svg' ),
110 ( "urn:oasis:names:tc:opendocument:xmlns:table:1.0", 'table' ),
111 ( "urn:oasis:names:tc:opendocument:xmlns:text:1.0", 'text' ),
112 ( "http://www.w3.org/1999/xlink", 'xlink' ),
113 ( "urn:oasis:names:tc:opendocument:xmlns:office:1.0", 'office' ),
116 visitorClass
= OdfVisitor