From 094e23351675a455639b6a313c43a344d69628e8 Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 4 Jul 2002 01:25:46 +0000 Subject: Added to project; trivial writer of the Docutils internal doctree in XML. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@244 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/writers/docutils_xml.py | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 docutils/writers/docutils_xml.py (limited to 'docutils/writers/docutils_xml.py') diff --git a/docutils/writers/docutils_xml.py b/docutils/writers/docutils_xml.py new file mode 100644 index 000000000..698908b27 --- /dev/null +++ b/docutils/writers/docutils_xml.py @@ -0,0 +1,43 @@ +#! /usr/bin/env python + +""" +:Authors: David Goodger +:Contact: goodger@users.sourceforge.net +:Revision: $Revision$ +:Date: $Date$ +:Copyright: This module has been placed in the public domain. + +Simple internal document tree Writer, writes Docutils XML. +""" + +__docformat__ = 'reStructuredText' + + +from docutils import writers + + +class Writer(writers.Writer): + + supported = ('xml',) + """Formats this writer supports.""" + + cmdline_options = ( + '"Docutils XML" Writer Options', + 'Warning: these options may adversely affect whitespace; use them ' + 'only for reading convenience.', + (('Generate XML with newlines before and after tags.', + ['--newlines'], {'action': 'store_true'}), + ('Generate XML with indents and newlines.', + ['--indents'], {'action': 'store_true'}),),) + + output = None + """Final translated form of `document`.""" + + def translate(self): + indent = newline = '' + if self.document.options.newlines: + newline = '\n' + if self.document.options.indents: + newline = '\n' + indent = ' ' + self.output = self.document.asdom().toprettyxml(indent, newline) -- cgit v1.2.1 From 0b1d625e609900031ac30d765b607e5aedb2f9b6 Mon Sep 17 00:00:00 2001 From: goodger Date: Tue, 24 Sep 2002 02:16:32 +0000 Subject: Added XML and doctype declarations. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@713 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/writers/docutils_xml.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'docutils/writers/docutils_xml.py') diff --git a/docutils/writers/docutils_xml.py b/docutils/writers/docutils_xml.py index 698908b27..21dd4a0d4 100644 --- a/docutils/writers/docutils_xml.py +++ b/docutils/writers/docutils_xml.py @@ -13,6 +13,7 @@ Simple internal document tree Writer, writes Docutils XML. __docformat__ = 'reStructuredText' +import docutils from docutils import writers @@ -33,11 +34,25 @@ class Writer(writers.Writer): output = None """Final translated form of `document`.""" + xml_declaration = '\n' + #xml_stylesheet = '\n' + doctype = ( + '\n') + generator = '\n' + def translate(self): + options = self.document.options indent = newline = '' - if self.document.options.newlines: + if options.newlines: newline = '\n' - if self.document.options.indents: + if options.indents: newline = '\n' indent = ' ' - self.output = self.document.asdom().toprettyxml(indent, newline) + output_prefix = [self.xml_declaration % options.output_encoding, + self.doctype, + self.generator % docutils.__version__] + docnode = self.document.asdom().childNodes[0] + self.output = (''.join(output_prefix) + + docnode.toprettyxml(indent, newline)) -- cgit v1.2.1 From 3873a3c91b0f82c9af3f321ee134a9dfd21e00d1 Mon Sep 17 00:00:00 2001 From: goodger Date: Wed, 25 Sep 2002 03:02:13 +0000 Subject: fixed git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@719 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/writers/docutils_xml.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docutils/writers/docutils_xml.py') diff --git a/docutils/writers/docutils_xml.py b/docutils/writers/docutils_xml.py index 21dd4a0d4..e005c7861 100644 --- a/docutils/writers/docutils_xml.py +++ b/docutils/writers/docutils_xml.py @@ -39,7 +39,7 @@ class Writer(writers.Writer): doctype = ( '\n') + ' "http://docutils.sourceforge.net/spec/docutils.dtd">\n') generator = '\n' def translate(self): -- cgit v1.2.1 From efdd39867964b92520a58c6796658895e412c441 Mon Sep 17 00:00:00 2001 From: goodger Date: Wed, 9 Oct 2002 00:51:53 +0000 Subject: changed docstring field lists into comments git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@778 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/writers/docutils_xml.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'docutils/writers/docutils_xml.py') diff --git a/docutils/writers/docutils_xml.py b/docutils/writers/docutils_xml.py index e005c7861..14b218dcd 100644 --- a/docutils/writers/docutils_xml.py +++ b/docutils/writers/docutils_xml.py @@ -1,12 +1,10 @@ -#! /usr/bin/env python +# Authors: David Goodger +# Contact: goodger@users.sourceforge.net +# Revision: $Revision$ +# Date: $Date$ +# Copyright: This module has been placed in the public domain. """ -:Authors: David Goodger -:Contact: goodger@users.sourceforge.net -:Revision: $Revision$ -:Date: $Date$ -:Copyright: This module has been placed in the public domain. - Simple internal document tree Writer, writes Docutils XML. """ -- cgit v1.2.1 From afeedfb343c2904e9357997d2a50f8f3cabb2568 Mon Sep 17 00:00:00 2001 From: goodger Date: Fri, 18 Oct 2002 04:55:21 +0000 Subject: Refactored names (options -> settings; .transform() -> .apply(); etc.); updated. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@825 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/writers/docutils_xml.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'docutils/writers/docutils_xml.py') diff --git a/docutils/writers/docutils_xml.py b/docutils/writers/docutils_xml.py index 14b218dcd..e5de9c48c 100644 --- a/docutils/writers/docutils_xml.py +++ b/docutils/writers/docutils_xml.py @@ -20,7 +20,7 @@ class Writer(writers.Writer): supported = ('xml',) """Formats this writer supports.""" - cmdline_options = ( + settings_spec = ( '"Docutils XML" Writer Options', 'Warning: these options may adversely affect whitespace; use them ' 'only for reading convenience.', @@ -41,14 +41,14 @@ class Writer(writers.Writer): generator = '\n' def translate(self): - options = self.document.options + settings = self.document.settings indent = newline = '' - if options.newlines: + if settings.newlines: newline = '\n' - if options.indents: + if settings.indents: newline = '\n' indent = ' ' - output_prefix = [self.xml_declaration % options.output_encoding, + output_prefix = [self.xml_declaration % settings.output_encoding, self.doctype, self.generator % docutils.__version__] docnode = self.document.asdom().childNodes[0] -- cgit v1.2.1 From 61e1c94b8ec784fa597445dc16a0b9e49da23134 Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 28 Nov 2002 03:30:19 +0000 Subject: Added "--no-doctype" and "--no-xml-declaration" options. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@979 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/writers/docutils_xml.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'docutils/writers/docutils_xml.py') diff --git a/docutils/writers/docutils_xml.py b/docutils/writers/docutils_xml.py index e5de9c48c..4ecbfb6c2 100644 --- a/docutils/writers/docutils_xml.py +++ b/docutils/writers/docutils_xml.py @@ -22,12 +22,18 @@ class Writer(writers.Writer): settings_spec = ( '"Docutils XML" Writer Options', - 'Warning: these options may adversely affect whitespace; use them ' - 'only for reading convenience.', + 'Warning: the --newlines and --indents options may adversely affect ' + 'whitespace; use them only for reading convenience.', (('Generate XML with newlines before and after tags.', ['--newlines'], {'action': 'store_true'}), ('Generate XML with indents and newlines.', - ['--indents'], {'action': 'store_true'}),),) + ['--indents'], {'action': 'store_true'}), + ('Omit the XML declaration. Use with caution.', + ['--no-xml-declaration'], {'dest': 'xml_declaration', 'default': 1, + 'action': 'store_false'}), + ('Omit the DOCTYPE declaration.', + ['--no-doctype'], {'dest': 'doctype_declaration', 'default': 1, + 'action': 'store_false'}),)) output = None """Final translated form of `document`.""" @@ -48,9 +54,13 @@ class Writer(writers.Writer): if settings.indents: newline = '\n' indent = ' ' - output_prefix = [self.xml_declaration % settings.output_encoding, - self.doctype, - self.generator % docutils.__version__] + output_prefix = [] + if settings.xml_declaration: + output_prefix.append( + self.xml_declaration % settings.output_encoding) + if settings.doctype_declaration: + output_prefix.append(self.doctype) + output_prefix.append(self.generator % docutils.__version__) docnode = self.document.asdom().childNodes[0] self.output = (''.join(output_prefix) + docnode.toprettyxml(indent, newline)) -- cgit v1.2.1 From ffa71e84747057982955e2bad3de2f8d3ed97c69 Mon Sep 17 00:00:00 2001 From: goodger Date: Wed, 27 Aug 2003 20:50:43 +0000 Subject: Updated for configuration file reorganization. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1645 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/writers/docutils_xml.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'docutils/writers/docutils_xml.py') diff --git a/docutils/writers/docutils_xml.py b/docutils/writers/docutils_xml.py index 4ecbfb6c2..0eaa4ed3c 100644 --- a/docutils/writers/docutils_xml.py +++ b/docutils/writers/docutils_xml.py @@ -35,6 +35,9 @@ class Writer(writers.Writer): ['--no-doctype'], {'dest': 'doctype_declaration', 'default': 1, 'action': 'store_false'}),)) + config_section = 'docutils_xml writer' + config_section_dependencies = ('writers',) + output = None """Final translated form of `document`.""" -- cgit v1.2.1 From 6bf1f3a52b24ff86ba93343d6a04e766601721de Mon Sep 17 00:00:00 2001 From: goodger Date: Mon, 1 Sep 2003 15:09:14 +0000 Subject: updated for setting validators git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1663 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/writers/docutils_xml.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'docutils/writers/docutils_xml.py') diff --git a/docutils/writers/docutils_xml.py b/docutils/writers/docutils_xml.py index 0eaa4ed3c..cc730d873 100644 --- a/docutils/writers/docutils_xml.py +++ b/docutils/writers/docutils_xml.py @@ -12,7 +12,7 @@ __docformat__ = 'reStructuredText' import docutils -from docutils import writers +from docutils import frontend, writers class Writer(writers.Writer): @@ -25,15 +25,19 @@ class Writer(writers.Writer): 'Warning: the --newlines and --indents options may adversely affect ' 'whitespace; use them only for reading convenience.', (('Generate XML with newlines before and after tags.', - ['--newlines'], {'action': 'store_true'}), + ['--newlines'], + {'action': 'store_true', 'validator': frontend.validate_boolean}), ('Generate XML with indents and newlines.', - ['--indents'], {'action': 'store_true'}), + ['--indents'], + {'action': 'store_true', 'validator': frontend.validate_boolean}), ('Omit the XML declaration. Use with caution.', - ['--no-xml-declaration'], {'dest': 'xml_declaration', 'default': 1, - 'action': 'store_false'}), + ['--no-xml-declaration'], + {'dest': 'xml_declaration', 'default': 1, 'action': 'store_false', + 'validator': frontend.validate_boolean}), ('Omit the DOCTYPE declaration.', - ['--no-doctype'], {'dest': 'doctype_declaration', 'default': 1, - 'action': 'store_false'}),)) + ['--no-doctype'], + {'dest': 'doctype_declaration', 'default': 1, + 'action': 'store_false', 'validator': frontend.validate_boolean}),)) config_section = 'docutils_xml writer' config_section_dependencies = ('writers',) -- cgit v1.2.1 From 6c18a0548558d3eefb532ef613a49533328dd357 Mon Sep 17 00:00:00 2001 From: wiemann Date: Sat, 5 Jun 2004 19:32:15 +0000 Subject: updated git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2223 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/writers/docutils_xml.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docutils/writers/docutils_xml.py') diff --git a/docutils/writers/docutils_xml.py b/docutils/writers/docutils_xml.py index cc730d873..1b1164977 100644 --- a/docutils/writers/docutils_xml.py +++ b/docutils/writers/docutils_xml.py @@ -50,7 +50,7 @@ class Writer(writers.Writer): doctype = ( '\n') + ' "http://docutils.sourceforge.net/docs/ref/docutils.dtd">\n') generator = '\n' def translate(self): -- cgit v1.2.1 From b30cbb0571acc552f53b3021ad9c63508a14330c Mon Sep 17 00:00:00 2001 From: wiemann Date: Sun, 19 Jun 2005 15:26:13 +0000 Subject: made xmlcharrefreplace the default output encoding error handler for HTML and XML writer git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@3512 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/writers/docutils_xml.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'docutils/writers/docutils_xml.py') diff --git a/docutils/writers/docutils_xml.py b/docutils/writers/docutils_xml.py index 1b1164977..2362e6b78 100644 --- a/docutils/writers/docutils_xml.py +++ b/docutils/writers/docutils_xml.py @@ -39,6 +39,8 @@ class Writer(writers.Writer): {'dest': 'doctype_declaration', 'default': 1, 'action': 'store_false', 'validator': frontend.validate_boolean}),)) + settings_defaults = {'output_encoding_error_handler': 'xmlcharrefreplace'} + config_section = 'docutils_xml writer' config_section_dependencies = ('writers',) -- cgit v1.2.1