# Copyright (C) 2013 Stefan Merten # This file is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published # by the Free Software Foundation; either version 2 of the License, # or (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA # 02111-1307, USA. """ Do conversion by using Python. """ __docformat__ = 'reStructuredText' # Formatted to be rendered by epydoc ############################################################################### ############################################################################### # Import import docutils.nodes from parsers.xml import XmlParser, XmlVisitor ############################################################################### ############################################################################### # Constants ############################################################################### ############################################################################### # Variables ############################################################################### ############################################################################### # Functions ############################################################################### ############################################################################### # Classes class OdfVisitor(XmlVisitor): """ Visitor class for visiting an ODF element tree. """ ########################################################################### # Presentation def visit_draw_page(self, elem): self.push(docutils.nodes.section()) def depart_draw_page(self, elem): self.pop() ########################################################################### # Lists def visit_text_list(self, elem): self.push(docutils.nodes.bullet_list(bullet="*")) raise SomeChildren(( ( "text", "list-item" ), )) def depart_text_list(self, elem): self.pop() def visit_text_listitem(self, elem): self.push(docutils.nodes.list_item()) raise SomeChildren(( ( "text", "list" ), ( "text", "p" ), )) def depart_text_listitem(self, elem): self.pop() ########################################################################### # Text def visit_text_p(self, elem): para = docutils.nodes.paragraph() if elem.text is not None: para.append(docutils.nodes.Text(elem.text)) self.push(para) # TODO tails of embedded inline elements must be considered def depart_text_p(self, elem): self.pop() # TODO Implement ############################################################################### class Parser(XmlParser): """ Parse the input file and translate it to the output file by Python. """ ns2Prefix = { u"http://www.w3.org/2001/xml-events": u'dom', u"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0": u'draw', u"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0": u'fo', u"urn:oasis:names:tc:opendocument:xmlns:presentation:1.0": u'presentation', u"urn:oasis:names:tc:opendocument:xmlns:script:1.0": u'script', u"urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0": u'smil', u"urn:oasis:names:tc:opendocument:xmlns:style:1.0": u'style', u"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0": u'svg', u"urn:oasis:names:tc:opendocument:xmlns:table:1.0": u'table', u"urn:oasis:names:tc:opendocument:xmlns:text:1.0": u'text', u"http://www.w3.org/1999/xlink": u'xlink', u"urn:oasis:names:tc:opendocument:xmlns:office:1.0": u'office', } visitorClass = OdfVisitor