Added transform for visible links.

This commit is contained in:
Roland Meister
2010-01-10 21:14:19 +01:00
parent 0ec66c2d3f
commit a880aa8f70
3 changed files with 43 additions and 0 deletions
+5
View File
@@ -71,6 +71,11 @@ The builder's "name" must be given to the **-b** command-line option of
details about it. For definition of the epub format, have a look at
`<http://www.idpf.org/specs.htm>`_ or `<http://en.wikipedia.org/wiki/EPUB>`_.
Some ebook readers do not show the link targets of references. Therefore
this builder adds the targets after the link when necessary. The display
of the URLs can be customized by adding CSS rules for the class
``link-target``.
Its name is ``epub``.
.. module:: sphinx.builders.latex
+25
View File
@@ -16,6 +16,7 @@ from os import path
import zipfile
from docutils import nodes
from docutils.transforms import Transform
from sphinx.builders.html import StandaloneHTMLBuilder
@@ -111,6 +112,29 @@ _media_types = {
}
# The transform to show link targets
class VisibleLinksTransform(Transform):
"""
Add the link target of referances to the text, unless it is already
present in the description.
"""
# This transform must run after the references transforms
default_priority = 680
def apply(self):
for ref in self.document.traverse(nodes.reference):
uri = ref.get('refuri', '')
if ( uri.startswith('http:') or uri.startswith('https:') or \
uri.startswith('ftp:') ) and uri not in ref.astext():
uri = ' [%s]' % uri
idx = ref.parent.index(ref) + 1
link = nodes.inline(uri, uri)
link['classes'].append('link-target')
ref.parent.insert(idx, link)
# The epub publisher
class EpubBuilder(StandaloneHTMLBuilder):
@@ -137,6 +161,7 @@ class EpubBuilder(StandaloneHTMLBuilder):
# the output files for epub must be .html only
self.out_suffix = '.html'
self.playorder = 0
self.app.add_transform(VisibleLinksTransform)
def get_theme_config(self):
return self.config.epub_theme, {}
+13
View File
@@ -420,6 +420,19 @@ div.footer a {
text-decoration: underline;
}
/* -- link-target ----------------------------------------------------------- */
.link-target {
font-size: 80%;
}
table .link-target {
/* Do not show links in tables, there is not enough space */
display: none;
}
/* -- font-face ------------------------------------------------------------- */
@font-face {
font-family: "LiberationNarrow";
font-style: normal;