Scaled images are now linked to their high resulution version.

This commit is contained in:
Sebastian Wiesner 2008-11-25 21:29:19 +01:00
parent 6ee8b51c01
commit 80740d68c4
2 changed files with 27 additions and 2 deletions

View File

@ -12,9 +12,11 @@
import os import os
import codecs import codecs
import shutil import shutil
import posixpath
import cPickle as pickle import cPickle as pickle
from os import path from os import path
from docutils import nodes
from docutils.io import DocTreeInput, StringOutput from docutils.io import DocTreeInput, StringOutput
from docutils.core import publish_parts from docutils.core import publish_parts
from docutils.utils import new_document from docutils.utils import new_document
@ -253,11 +255,11 @@ class StandaloneHTMLBuilder(Builder):
) )
def write_doc(self, docname, doctree): def write_doc(self, docname, doctree):
self.post_process_images(doctree)
destination = StringOutput(encoding='utf-8') destination = StringOutput(encoding='utf-8')
doctree.settings = self.docsettings doctree.settings = self.docsettings
self.imgpath = relative_uri(self.get_target_uri(docname), '_images') self.imgpath = relative_uri(self.get_target_uri(docname), '_images')
self.post_process_images(doctree)
self.dlpath = relative_uri(self.get_target_uri(docname), '_downloads') self.dlpath = relative_uri(self.get_target_uri(docname), '_downloads')
self.docwriter.write(doctree, destination) self.docwriter.write(doctree, destination)
self.docwriter.assemble_parts() self.docwriter.assemble_parts()
@ -486,6 +488,29 @@ class StandaloneHTMLBuilder(Builder):
# clean up theme stuff # clean up theme stuff
self.theme.cleanup() self.theme.cleanup()
def post_process_images(self, doctree):
"""
Pick the best candiate for an image and link down-scaled images to
their high res version.
"""
Builder.post_process_images(self, doctree)
for node in doctree.traverse(nodes.image):
if not node.has_key('scale') or \
isinstance(node.parent, nodes.reference):
# docutils does unfortunately not preserve the
# ``target`` attribute on images, so we need to check
# the parent node here.
continue
uri = node['uri']
reference = nodes.reference()
if uri in self.images:
reference['refuri'] = posixpath.join(self.imgpath,
self.images[uri])
else:
reference['refuri'] = uri
node.replace_self(reference)
reference.append(node)
def get_outdated_docs(self): def get_outdated_docs(self):
if self.templates: if self.templates:
template_mtime = self.templates.newest_template_mtime() template_mtime = self.templates.newest_template_mtime()

View File

@ -82,7 +82,7 @@ div.sphinxsidebar input {
font-size: 1em; font-size: 1em;
} }
img.logo { img {
border: 0; border: 0;
} }