diff options
author | Jonathan Waltman <jonathan.waltman@gmail.com> | 2012-12-04 21:10:15 -0600 |
---|---|---|
committer | Jonathan Waltman <jonathan.waltman@gmail.com> | 2012-12-04 21:10:15 -0600 |
commit | 8ac4aa62829391ca58fc0fd7b38e8d1d9c97a59f (patch) | |
tree | 55c818ca911dda55edc61e0a49e7c2b060b0046c /sphinx/writers/xml.py | |
parent | 1e66d33c7b8b656c0fc46ea3292e8e943fa9e30f (diff) | |
download | sphinx-git-8ac4aa62829391ca58fc0fd7b38e8d1d9c97a59f.tar.gz |
Add Docutils-native XML and pseudo-XML builders
Diffstat (limited to 'sphinx/writers/xml.py')
-rw-r--r-- | sphinx/writers/xml.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/sphinx/writers/xml.py b/sphinx/writers/xml.py new file mode 100644 index 000000000..02becb731 --- /dev/null +++ b/sphinx/writers/xml.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- +""" + sphinx.writers.xml + ~~~~~~~~~~~~~~~~~~ + + Docutils-native XML and pseudo-XML writers. + + :copyright: Copyright 2007-2012 by the Sphinx team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +from docutils import writers +from docutils.writers.docutils_xml import Writer as BaseXMLWriter +from docutils.writers.docutils_xml import XMLTranslator as BaseXMLTranslator + + +class XMLWriter(BaseXMLWriter): + + def __init__(self, builder): + BaseXMLWriter.__init__(self) + self.builder = builder + + def translate(self, *args, **kwargs): + self.document.settings.newlines = \ + self.document.settings.indents = \ + self.builder.env.config.xml_pretty + self.document.settings.xml_declaration = True + self.document.settings.doctype_declaration = True + return BaseXMLWriter.translate(self) + + +class XMLTranslator(BaseXMLTranslator): + def __init__(self, builder, doc): + BaseXMLTranslator.__init__(self, doc) + self.builder = builder + + +class PseudoXMLWriter(writers.Writer): + + supported = ('pprint', 'pformat', 'pseudoxml') + """Formats this writer supports.""" + + config_section = 'pseudoxml writer' + config_section_dependencies = ('writers',) + + output = None + """Final translated form of `document`.""" + + def __init__(self, builder): + writers.Writer.__init__(self) + self.builder = builder + + def translate(self): + self.output = self.document.pformat() + + def supports(self, format): + """This writer supports all format-specific elements.""" + return True |