summaryrefslogtreecommitdiff
path: root/sphinx/builders
diff options
context:
space:
mode:
authorshimizukawa <shimizukawa@gmail.com>2012-12-10 10:18:32 +0900
committershimizukawa <shimizukawa@gmail.com>2012-12-10 10:18:32 +0900
commitd45dcfbd7e5add4495a7e31ee53e672ee180d534 (patch)
treee3ccbee28f06bfccb66ab2c54cb3b1648409e704 /sphinx/builders
parent207e12471f451fee53a95ca6918c93abfef3a632 (diff)
parent5818df7941b73abecdb1b399fee7956ea283d698 (diff)
downloadsphinx-d45dcfbd7e5add4495a7e31ee53e672ee180d534.tar.gz
merge heads
Diffstat (limited to 'sphinx/builders')
-rw-r--r--sphinx/builders/__init__.py2
-rw-r--r--sphinx/builders/html.py3
-rw-r--r--sphinx/builders/linkcheck.py3
-rw-r--r--sphinx/builders/xml.py85
4 files changed, 91 insertions, 2 deletions
diff --git a/sphinx/builders/__init__.py b/sphinx/builders/__init__.py
index 5240a1c7..4355b801 100644
--- a/sphinx/builders/__init__.py
+++ b/sphinx/builders/__init__.py
@@ -334,4 +334,6 @@ BUILTIN_BUILDERS = {
'linkcheck': ('linkcheck', 'CheckExternalLinksBuilder'),
'websupport': ('websupport', 'WebSupportBuilder'),
'gettext': ('gettext', 'MessageCatalogBuilder'),
+ 'xml': ('xml', 'XMLBuilder'),
+ 'pseudoxml': ('xml', 'PseudoXMLBuilder'),
}
diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py
index 81840374..f5218673 100644
--- a/sphinx/builders/html.py
+++ b/sphinx/builders/html.py
@@ -610,7 +610,8 @@ class StandaloneHTMLBuilder(Builder):
"""
Builder.post_process_images(self, doctree)
for node in doctree.traverse(nodes.image):
- if not node.has_key('scale') or \
+ scale_keys = ('scale', 'width', 'height')
+ if not any((key in node) for key in scale_keys) or \
isinstance(node.parent, nodes.reference):
# docutils does unfortunately not preserve the
# ``target`` attribute on images, so we need to check
diff --git a/sphinx/builders/linkcheck.py b/sphinx/builders/linkcheck.py
index a8adcdac..bcf42741 100644
--- a/sphinx/builders/linkcheck.py
+++ b/sphinx/builders/linkcheck.py
@@ -102,7 +102,8 @@ class CheckExternalLinksBuilder(Builder):
def check():
# check for various conditions without bothering the network
- if len(uri) == 0 or uri[0] == '#' or uri[0:7] == 'mailto:' or uri[0:4] == 'ftp:':
+ if len(uri) == 0 or uri[0] == '#' or \
+ uri[0:7] == 'mailto:' or uri[0:4] == 'ftp:':
return 'unchecked', ''
elif not (uri[0:5] == 'http:' or uri[0:6] == 'https:'):
return 'local', ''
diff --git a/sphinx/builders/xml.py b/sphinx/builders/xml.py
new file mode 100644
index 00000000..74c1fc06
--- /dev/null
+++ b/sphinx/builders/xml.py
@@ -0,0 +1,85 @@
+# -*- coding: utf-8 -*-
+"""
+ sphinx.builders.xml
+ ~~~~~~~~~~~~~~~~~~~
+
+ Docutils-native XML and pseudo-XML builders.
+
+ :copyright: Copyright 2007-2012 by the Sphinx team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+
+import codecs
+from os import path
+
+from docutils.io import StringOutput
+
+from sphinx.builders import Builder
+from sphinx.util.osutil import ensuredir, os_path
+from sphinx.writers.xml import XMLWriter, PseudoXMLWriter
+
+class XMLBuilder(Builder):
+ """
+ Builds Docutils-native XML.
+ """
+ name = 'xml'
+ format = 'xml'
+ out_suffix = '.xml'
+
+ _writer_class = XMLWriter
+
+ def init(self):
+ pass
+
+ def get_outdated_docs(self):
+ for docname in self.env.found_docs:
+ if docname not in self.env.all_docs:
+ yield docname
+ continue
+ targetname = self.env.doc2path(docname, self.outdir,
+ self.out_suffix)
+ try:
+ targetmtime = path.getmtime(targetname)
+ except Exception:
+ targetmtime = 0
+ try:
+ srcmtime = path.getmtime(self.env.doc2path(docname))
+ if srcmtime > targetmtime:
+ yield docname
+ except EnvironmentError:
+ # source doesn't exist anymore
+ pass
+
+ def get_target_uri(self, docname, typ=None):
+ return ''
+
+ def prepare_writing(self, docnames):
+ self.writer = self._writer_class(self)
+
+ def write_doc(self, docname, doctree):
+ destination = StringOutput(encoding='utf-8')
+ self.writer.write(doctree, destination)
+ outfilename = path.join(self.outdir, os_path(docname) + self.out_suffix)
+ ensuredir(path.dirname(outfilename))
+ try:
+ f = codecs.open(outfilename, 'w', 'utf-8')
+ try:
+ f.write(self.writer.output)
+ finally:
+ f.close()
+ except (IOError, OSError), err:
+ self.warn("error writing file %s: %s" % (outfilename, err))
+
+ def finish(self):
+ pass
+
+
+class PseudoXMLBuilder(XMLBuilder):
+ """
+ Builds pseudo-XML for display purposes.
+ """
+ name = 'pseudoxml'
+ format = 'pseudoxml'
+ out_suffix = '.pseudoxml'
+
+ _writer_class = PseudoXMLWriter