[Python-modules-commits] [sphinx] 01/17: Import sphinx_1.3.6.orig.tar.gz
Dmitry Shachnev
mitya57 at moszumanska.debian.org
Wed Mar 2 07:30:01 UTC 2016
This is an automated email from the git hooks/post-receive script.
mitya57 pushed a commit to branch master
in repository sphinx.
commit cca571bd757bd9a1ab039154581b689c7986ee29
Author: Dmitry Shachnev <mitya57 at gmail.com>
Date: Wed Mar 2 09:54:58 2016 +0300
Import sphinx_1.3.6.orig.tar.gz
---
CHANGES | 33 +++++-
PKG-INFO | 2 +-
Sphinx.egg-info/PKG-INFO | 2 +-
Sphinx.egg-info/SOURCES.txt | 3 +
doc/intl.rst | 13 ++-
doc/templating.rst | 5 +
sphinx/__init__.py | 6 +-
sphinx/application.py | 5 +-
sphinx/builders/html.py | 4 +
sphinx/cmdline.py | 8 ++
sphinx/domains/std.py | 3 +-
sphinx/environment.py | 93 ++--------------
sphinx/ext/autodoc.py | 9 +-
sphinx/ext/mathbase.py | 7 +-
sphinx/highlighting.py | 4 +-
sphinx/io.py | 121 +++++++++++++++++++++
sphinx/quickstart.py | 5 +-
sphinx/search/__init__.py | 2 +
sphinx/themes/agogo/static/agogo.css_t | 10 ++
sphinx/themes/haiku/static/haiku.css_t | 5 +
sphinx/themes/scrolls/static/scrolls.css_t | 10 ++
sphinx/themes/traditional/static/traditional.css_t | 10 ++
sphinx/transforms.py | 60 +++++-----
sphinx/util/nodes.py | 5 +-
sphinx/writers/html.py | 2 +-
sphinx/writers/latex.py | 39 ++++---
tests/roots/test-footnotes/bar.rst | 6 +
tests/roots/test-footnotes/baz.rst | 6 +
tests/roots/test-footnotes/index.rst | 8 ++
tests/test_build_html.py | 17 ++-
tests/test_build_latex.py | 68 ++++++++++--
tests/test_build_texinfo.py | 1 -
tests/test_search.py | 13 +++
33 files changed, 412 insertions(+), 173 deletions(-)
diff --git a/CHANGES b/CHANGES
index 8b75442..afd5cc9 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,29 @@
+Release 1.3.6 (released Feb 29, 2016)
+=====================================
+
+Features added
+--------------
+
+* #1873, #1876, #2278: Add ``page_source_suffix`` html context variable. This should be
+ introduced with :confval:`source_parsers` feature. Thanks for Eric Holscher.
+
+
+Bugs fixed
+----------
+
+* #2265: Fix babel is used in spite of disabling it on ``latex_elements``
+* #2295: Avoid mutating dictionary errors while enumerating members in autodoc
+ with Python 3
+* #2291: Fix pdflatex "Counter too large" error from footnotes inside tables of contents
+* #2292: Fix some footnotes disappear from LaTeX output
+* #2287: ``sphinx.transforms.Locale`` always uses rst parser. Sphinx i18n feature should
+ support parsers that specified source_parsers.
+* #2290: Fix ``sphinx.ext.mathbase`` use of amsfonts may break user choice of math fonts
+* #2324: Print a hint how to increase the recursion limit when it is hit.
+* #1565, #2229: Revert new warning; the new warning will be triggered from version 1.4 on.
+* #2329: Refresh environment forcely if source directory has changed.
+* #2019: Fix the domain objects in search result are not escaped
+
Release 1.3.5 (released Jan 24, 2016)
=====================================
@@ -7,12 +33,13 @@ Bugs fixed
* Fix line numbers was not shown on warnings in LaTeX and texinfo builders
* Fix filenames were not shown on warnings of citations
* Fix line numbers was not shown on warnings in LaTeX and texinfo builders
-* Fix line numbers was not shown on warnings of indecies
-* #2026: Fix LaTeX builder rais error if parsed-literal includes links
+* Fix line numbers was not shown on warnings of indices
+* #2026: Fix LaTeX builder raises error if parsed-literal includes links
* #2243: Ignore strange docstring types for classes, do not crash
* #2247: Fix #2205 breaks make html for definition list with classifiers
that contains regular-expression like string
-* #1565: Show warning if Pygments throws an ErrorToken
+* #1565: Sphinx will now emit a warning that highlighting was skipped if the syntax
+ is incorrect for `code-block`, `literalinclude` and so on.
* #2211: Fix paragraphs in table cell doesn't work in Latex output
* #2253: ``:pyobject:`` option of ``literalinclude`` directive can't detect indented
body block when the block starts with blank or comment lines.
diff --git a/PKG-INFO b/PKG-INFO
index f74dfb1..f75a21f 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: Sphinx
-Version: 1.3.5
+Version: 1.3.6
Summary: Python documentation generator
Home-page: http://sphinx-doc.org/
Author: Georg Brandl
diff --git a/Sphinx.egg-info/PKG-INFO b/Sphinx.egg-info/PKG-INFO
index f74dfb1..f75a21f 100644
--- a/Sphinx.egg-info/PKG-INFO
+++ b/Sphinx.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: Sphinx
-Version: 1.3.5
+Version: 1.3.6
Summary: Python documentation generator
Home-page: http://sphinx-doc.org/
Author: Georg Brandl
diff --git a/Sphinx.egg-info/SOURCES.txt b/Sphinx.egg-info/SOURCES.txt
index 37f3186..4c11d5d 100644
--- a/Sphinx.egg-info/SOURCES.txt
+++ b/Sphinx.egg-info/SOURCES.txt
@@ -133,6 +133,7 @@ sphinx/config.py
sphinx/environment.py
sphinx/errors.py
sphinx/highlighting.py
+sphinx/io.py
sphinx/jinja2glue.py
sphinx/make_mode.py
sphinx/pygments_styles.py
@@ -675,6 +676,8 @@ tests/roots/test-ext-viewcode/objects.rst
tests/roots/test-ext-viewcode/spam/__init__.py
tests/roots/test-ext-viewcode/spam/mod1.py
tests/roots/test-ext-viewcode/spam/mod2.py
+tests/roots/test-footnotes/bar.rst
+tests/roots/test-footnotes/baz.rst
tests/roots/test-footnotes/conf.py
tests/roots/test-footnotes/index.rst
tests/roots/test-footnotes/rimg.png
diff --git a/doc/intl.rst b/doc/intl.rst
index bd4f9e8..2290b0f 100644
--- a/doc/intl.rst
+++ b/doc/intl.rst
@@ -106,17 +106,23 @@ This section describe a easy way to translate with sphinx-intl.
#. Translate your po files under `./locale/<lang>/LC_MESSAGES/`.
-#. Build mo files and make translated document.
+#. make translated document.
You need a :confval:`language` parameter in ``conf.py`` or you may also
specify the parameter on the command line::
- $ sphinx-intl build
$ make -e SPHINXOPTS="-D language='de'" html
Congratulations! You got the translated documentation in the ``_build/html``
directory.
+.. versionadded:: 1.3
+
+ sphinx-build that is invoked by make command will build po files into mo files.
+
+ If you are using 1.2.x or earlier, please invoke ``sphinx-intl build`` command
+ before make command.
+
Translating
^^^^^^^^^^^
@@ -251,9 +257,8 @@ easy to fetch and push translations.
...
Done.
- Build po files into mo and make html::
+ Invoke make html::
- $ sphinx-intl build
$ make -e SPHINXOPTS="-D language='de'" html
diff --git a/doc/templating.rst b/doc/templating.rst
index 19ed148..5286e03 100644
--- a/doc/templating.rst
+++ b/doc/templating.rst
@@ -399,3 +399,8 @@ are in HTML form), these variables are also available:
* ``includehidden`` (``False`` by default): if true, the TOC tree will also
contain hidden entries.
+
+.. data:: page_source_suffix
+
+ The suffix of the file that was rendered. Since we support a list of :confval:`source_suffix`,
+ this will allow you to properly link to the original source file.
diff --git a/sphinx/__init__.py b/sphinx/__init__.py
index a6e8b43..8b64ecf 100644
--- a/sphinx/__init__.py
+++ b/sphinx/__init__.py
@@ -15,13 +15,13 @@
import sys
from os import path
-__version__ = '1.3.5'
-__released__ = '1.3.5' # used when Sphinx builds its own docs
+__version__ = '1.3.6'
+__released__ = '1.3.6' # used when Sphinx builds its own docs
# version info for better programmatic use
# possible values for 3rd element: 'alpha', 'beta', 'rc', 'final'
# 'final' has 0 as the last element
-version_info = (1, 3, 5, 'final', 0)
+version_info = (1, 3, 6, 'final', 0)
package_dir = path.abspath(path.dirname(__file__))
diff --git a/sphinx/application.py b/sphinx/application.py
index 957a1be..c1da690 100644
--- a/sphinx/application.py
+++ b/sphinx/application.py
@@ -35,7 +35,8 @@ from sphinx.errors import SphinxError, SphinxWarning, ExtensionError, \
from sphinx.domains import ObjType, BUILTIN_DOMAINS
from sphinx.domains.std import GenericObject, Target, StandardDomain
from sphinx.builders import BUILTIN_BUILDERS
-from sphinx.environment import BuildEnvironment, SphinxStandaloneReader
+from sphinx.environment import BuildEnvironment
+from sphinx.io import SphinxStandaloneReader
from sphinx.util import pycompat # noqa: imported for side-effects
from sphinx.util import import_object
from sphinx.util.tags import Tags
@@ -220,7 +221,7 @@ class Sphinx(object):
try:
self.info(bold('loading pickled environment... '), nonl=True)
self.env = BuildEnvironment.frompickle(
- self.config, path.join(self.doctreedir, ENV_PICKLE_FILENAME))
+ self.srcdir, self.config, path.join(self.doctreedir, ENV_PICKLE_FILENAME))
self.env.domains = {}
for domain in self.domains.keys():
# this can raise if the data version doesn't fit
diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py
index 8dcb905..e247f33 100644
--- a/sphinx/builders/html.py
+++ b/sphinx/builders/html.py
@@ -408,6 +408,9 @@ class StandaloneHTMLBuilder(Builder):
# metadata for the document
meta = self.env.metadata.get(docname)
+ # Suffix for the document
+ source_suffix = '.' + self.env.doc2path(docname).split('.')[-1]
+
# local TOC and global TOC tree
self_toc = self.env.get_toc_for(docname, self)
toc = self.render_partial(self_toc)['fragment']
@@ -425,6 +428,7 @@ class StandaloneHTMLBuilder(Builder):
toc = toc,
# only display a TOC if there's more than one item to show
display_toc = (self.env.toc_num_entries[docname] > 1),
+ page_source_suffix = source_suffix,
)
def write_doc(self, docname, doctree):
diff --git a/sphinx/cmdline.py b/sphinx/cmdline.py
index 21422be..2ba4c4f 100644
--- a/sphinx/cmdline.py
+++ b/sphinx/cmdline.py
@@ -270,6 +270,14 @@ def main(argv):
print(red('The full traceback has been saved in %s, if you want '
'to report the issue to the developers.' % tbpath),
file=error)
+ elif isinstance(err, RuntimeError) and 'recursion depth' in str(err):
+ print(red('Recursion error:'), file=error)
+ print(terminal_safe(text_type(err)), file=error)
+ print(file=error)
+ print('This can happen with very large or deeply nested source '
+ 'files. You can carefully increase the default Python '
+ 'recursion limit of 1000 in conf.py with e.g.:', file=error)
+ print(' import sys; sys.setrecursionlimit(1500)', file=error)
else:
print(red('Exception occurred:'), file=error)
print(format_exception_cut_frames().rstrip(), file=error)
diff --git a/sphinx/domains/std.py b/sphinx/domains/std.py
index 425b62a..a6ed259 100644
--- a/sphinx/domains/std.py
+++ b/sphinx/domains/std.py
@@ -453,7 +453,7 @@ class StandardDomain(Domain):
'productionlist': ProductionList,
}
roles = {
- 'option': OptionXRefRole(warn_dangling=True),
+ 'option': OptionXRefRole(),
'envvar': EnvVarXRefRole(),
# links to tokens in grammar productions
'token': XRefRole(),
@@ -491,7 +491,6 @@ class StandardDomain(Domain):
'the label must precede a section header)',
'numref': 'undefined label: %(target)s',
'keyword': 'unknown keyword: %(target)s',
- 'option': 'unknown option: %(target)s',
}
def clear_doc(self, docname):
diff --git a/sphinx/environment.py b/sphinx/environment.py
index 8d0789c..ebe167d 100644
--- a/sphinx/environment.py
+++ b/sphinx/environment.py
@@ -23,24 +23,23 @@ from os import path
from glob import glob
from itertools import groupby
-from six import iteritems, itervalues, text_type, class_types, string_types, next
+from six import iteritems, itervalues, text_type, class_types, next
from six.moves import cPickle as pickle
from docutils import nodes
-from docutils.io import FileInput, NullOutput
+from docutils.io import NullOutput
from docutils.core import Publisher
from docutils.utils import Reporter, relative_path, get_source_line
-from docutils.readers import standalone
from docutils.parsers.rst import roles, directives
from docutils.parsers.rst.languages import en as english
from docutils.parsers.rst.directives.html import MetaBody
-from docutils.writers import UnfilteredWriter
from docutils.frontend import OptionParser
from sphinx import addnodes
+from sphinx.io import SphinxStandaloneReader, SphinxDummyWriter, SphinxFileInput
from sphinx.util import url_re, get_matching_docs, docname_join, split_into, \
- FilenameUniqDict, get_figtype, import_object, split_index_msg
+ FilenameUniqDict, get_figtype, split_index_msg
from sphinx.util.nodes import clean_astext, make_refnode, WarningStream, is_translatable
-from sphinx.util.osutil import SEP, getcwd, fs_encoding
+from sphinx.util.osutil import SEP, getcwd, fs_encoding, ensuredir
from sphinx.util.i18n import find_catalog_files
from sphinx.util.console import bold, purple
from sphinx.util.matching import compile_matchers
@@ -49,12 +48,7 @@ from sphinx.util.websupport import is_commentable
from sphinx.errors import SphinxError, ExtensionError
from sphinx.locale import _
from sphinx.versioning import add_uids, merge_doctrees
-from sphinx.transforms import (
- DefaultSubstitutions, MoveModuleTargets, ApplySourceWorkaround,
- HandleCodeBlocks, AutoNumbering, SortIds, CitationReferences, Locale,
- RemoveTranslatableInline, SphinxContentsFilter, ExtraTranslatableNodes,
-)
-
+from sphinx.transforms import SphinxContentsFilter
orig_role_function = roles.role
orig_directive_function = directives.directive
@@ -97,73 +91,6 @@ class NoUri(Exception):
pass
-class SphinxStandaloneReader(standalone.Reader):
- """
- Add our own transforms.
- """
- transforms = [ApplySourceWorkaround, ExtraTranslatableNodes, Locale, CitationReferences,
- DefaultSubstitutions, MoveModuleTargets, HandleCodeBlocks,
- AutoNumbering, SortIds, RemoveTranslatableInline]
-
- def __init__(self, parsers={}, *args, **kwargs):
- standalone.Reader.__init__(self, *args, **kwargs)
- self.parser_map = {}
- for suffix, parser_class in parsers.items():
- if isinstance(parser_class, string_types):
- parser_class = import_object(parser_class, 'source parser')
- self.parser_map[suffix] = parser_class()
-
- def read(self, source, parser, settings):
- self.source = source
-
- for suffix in self.parser_map:
- if source.source_path.endswith(suffix):
- self.parser = self.parser_map[suffix]
- break
-
- if not self.parser:
- self.parser = parser
- self.settings = settings
- self.input = self.source.read()
- self.parse()
- return self.document
-
- def get_transforms(self):
- return standalone.Reader.get_transforms(self) + self.transforms
-
-
-class SphinxDummyWriter(UnfilteredWriter):
- supported = ('html',) # needed to keep "meta" nodes
-
- def translate(self):
- pass
-
-
-class SphinxFileInput(FileInput):
- def __init__(self, app, env, *args, **kwds):
- self.app = app
- self.env = env
- kwds['error_handler'] = 'sphinx' # py3: handle error on open.
- FileInput.__init__(self, *args, **kwds)
-
- def decode(self, data):
- if isinstance(data, text_type): # py3: `data` already decoded.
- return data
- return data.decode(self.encoding, 'sphinx') # py2: decoding
-
- def read(self):
- data = FileInput.read(self)
- if self.app:
- arg = [data]
- self.app.emit('source-read', self.env.docname, arg)
- data = arg[0]
- if self.env.config.rst_epilog:
- data = data + '\n' + self.env.config.rst_epilog + '\n'
- if self.env.config.rst_prolog:
- data = self.env.config.rst_prolog + '\n' + data
- return data
-
-
class BuildEnvironment:
"""
The environment in which the ReST files are translated.
@@ -174,7 +101,7 @@ class BuildEnvironment:
# --------- ENVIRONMENT PERSISTENCE ----------------------------------------
@staticmethod
- def frompickle(config, filename):
+ def frompickle(srcdir, config, filename):
picklefile = open(filename, 'rb')
try:
env = pickle.load(picklefile)
@@ -182,6 +109,8 @@ class BuildEnvironment:
picklefile.close()
if env.version != ENV_VERSION:
raise IOError('build environment version not current')
+ if env.srcdir != srcdir:
+ raise IOError('source directory has changed')
env.config.values = config.values
return env
@@ -855,9 +784,7 @@ class BuildEnvironment:
# save the parsed doctree
doctree_filename = self.doc2path(docname, self.doctreedir,
'.doctree')
- dirname = path.dirname(doctree_filename)
- if not path.isdir(dirname):
- os.makedirs(dirname)
+ ensuredir(path.dirname(doctree_filename))
f = open(doctree_filename, 'wb')
try:
pickle.dump(doctree, f, pickle.HIGHEST_PROTOCOL)
diff --git a/sphinx/ext/autodoc.py b/sphinx/ext/autodoc.py
index f906d96..8cd8845 100644
--- a/sphinx/ext/autodoc.py
+++ b/sphinx/ext/autodoc.py
@@ -17,7 +17,8 @@ import inspect
import traceback
from types import FunctionType, BuiltinFunctionType, MethodType
-from six import iteritems, itervalues, text_type, class_types, string_types
+from six import PY2, iterkeys, iteritems, itervalues, text_type, class_types, \
+ string_types
from docutils import nodes
from docutils.utils import assemble_option_dict
from docutils.statemachine import ViewList
@@ -410,6 +411,8 @@ class Documenter(object):
else:
errmsg += '; the following exception was raised:\n%s' % \
traceback.format_exc()
+ if PY2:
+ errmsg = errmsg.decode('utf-8')
dbg(errmsg)
self.directive.warn(errmsg)
self.env.note_reread()
@@ -598,7 +601,7 @@ class Documenter(object):
# __dict__ contains only the members directly defined in
# the class (but get them via getattr anyway, to e.g. get
# unbound method objects instead of function objects);
- # using keys() because apparently there are objects for which
+ # using list(iterkeys()) because apparently there are objects for which
# __dict__ changes while getting attributes
try:
obj_dict = self.get_attr(self.object, '__dict__')
@@ -606,7 +609,7 @@ class Documenter(object):
members = []
else:
members = [(mname, self.get_attr(self.object, mname, None))
- for mname in obj_dict.keys()]
+ for mname in list(iterkeys(obj_dict))]
membernames = set(m[0] for m in members)
# add instance attributes from the analyzer
for aname in analyzed_member_names:
diff --git a/sphinx/ext/mathbase.py b/sphinx/ext/mathbase.py
index 14b1a8a..35f633c 100644
--- a/sphinx/ext/mathbase.py
+++ b/sphinx/ext/mathbase.py
@@ -207,6 +207,11 @@ def number_equations(app, doctree, docname):
node[0] = nodes.Text(num, num)
+def setup_amsfont(app):
+ # use amsfonts if users do not configure latex_elements['amsfonts']
+ app.config.latex_elements.setdefault('amsfonts', r'\usepackage{amsfonts}')
+
+
def setup_math(app, htmlinlinevisitors, htmldisplayvisitors):
app.add_node(math,
latex=(latex_visit_math, None),
@@ -230,4 +235,4 @@ def setup_math(app, htmlinlinevisitors, htmldisplayvisitors):
app.add_role('eq', eq_role)
app.add_directive('math', MathDirective)
app.connect('doctree-resolved', number_equations)
- app.add_latex_package('amsfonts')
+ app.connect('builder-inited', setup_amsfont)
diff --git a/sphinx/highlighting.py b/sphinx/highlighting.py
index aa78b5b..5df2d29 100644
--- a/sphinx/highlighting.py
+++ b/sphinx/highlighting.py
@@ -186,9 +186,7 @@ class PygmentsBridge(object):
except ErrorToken as exc:
# this is most probably not the selected language,
# so let it pass unhighlighted
- if warn:
- warn('Could not parse literal_block as "%s". highlighting skipped.' % lang)
- else:
+ if not warn:
raise exc
hlsource = highlight(source, lexers['none'], formatter)
if self.dest == 'html':
diff --git a/sphinx/io.py b/sphinx/io.py
new file mode 100644
index 0000000..4b9df41
--- /dev/null
+++ b/sphinx/io.py
@@ -0,0 +1,121 @@
+# -*- coding: utf-8 -*-
+"""
+ sphinx.io
+ ~~~~~~~~~
+
+ Input/Output files
+
+ :copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+from docutils.io import FileInput
+from docutils.readers import standalone
+from docutils.writers import UnfilteredWriter
+from six import string_types, text_type
+
+from sphinx.transforms import ApplySourceWorkaround, ExtraTranslatableNodes, Locale, \
+ CitationReferences, DefaultSubstitutions, MoveModuleTargets, HandleCodeBlocks, \
+ AutoNumbering, SortIds, RemoveTranslatableInline
+from sphinx.util import import_object
+
+
+class SphinxBaseReader(standalone.Reader):
+ """
+ Add our source parsers
+ """
+ def __init__(self, parsers={}, *args, **kwargs):
+ standalone.Reader.__init__(self, *args, **kwargs)
+ self.parser_map = {}
+ for suffix, parser_class in parsers.items():
+ if isinstance(parser_class, string_types):
+ parser_class = import_object(parser_class, 'source parser')
+ self.parser_map[suffix] = parser_class()
+
+ def read(self, source, parser, settings):
+ self.source = source
+
+ for suffix in self.parser_map:
+ if source.source_path.endswith(suffix):
+ self.parser = self.parser_map[suffix]
+ break
+
+ if not self.parser:
+ self.parser = parser
+ self.settings = settings
+ self.input = self.source.read()
+ self.parse()
+ return self.document
+
+ def get_transforms(self):
+ return standalone.Reader.get_transforms(self) + self.transforms
+
+
+class SphinxStandaloneReader(SphinxBaseReader):
+ """
+ Add our own transforms.
+ """
+ transforms = [ApplySourceWorkaround, ExtraTranslatableNodes, Locale, CitationReferences,
+ DefaultSubstitutions, MoveModuleTargets, HandleCodeBlocks,
+ AutoNumbering, SortIds, RemoveTranslatableInline]
+
+
+class SphinxI18nReader(SphinxBaseReader):
+ """
+ Replacer for document.reporter.get_source_and_line method.
+
+ reST text lines for translation do not have the original source line number.
+ This class provides the correct line numbers when reporting.
+ """
+
+ transforms = [ApplySourceWorkaround, ExtraTranslatableNodes, CitationReferences,
+ DefaultSubstitutions, MoveModuleTargets, HandleCodeBlocks,
+ AutoNumbering, SortIds, RemoveTranslatableInline]
+
+ def __init__(self, *args, **kwargs):
+ SphinxBaseReader.__init__(self, *args, **kwargs)
+ self.lineno = None
+
+ def set_lineno_for_reporter(self, lineno):
+ self.lineno = lineno
+
+ def new_document(self):
+ document = SphinxBaseReader.new_document(self)
+ reporter = document.reporter
+
+ def get_source_and_line(lineno=None):
+ return reporter.source, self.lineno
+
+ reporter.get_source_and_line = get_source_and_line
+ return document
+
+
+class SphinxDummyWriter(UnfilteredWriter):
+ supported = ('html',) # needed to keep "meta" nodes
+
+ def translate(self):
+ pass
+
+
+class SphinxFileInput(FileInput):
+ def __init__(self, app, env, *args, **kwds):
+ self.app = app
+ self.env = env
+ kwds['error_handler'] = 'sphinx' # py3: handle error on open.
+ FileInput.__init__(self, *args, **kwds)
+
+ def decode(self, data):
+ if isinstance(data, text_type): # py3: `data` already decoded.
+ return data
+ return data.decode(self.encoding, 'sphinx') # py2: decoding
+
+ def read(self):
+ data = FileInput.read(self)
+ if self.app:
+ arg = [data]
+ self.app.emit('source-read', self.env.docname, arg)
+ data = arg[0]
+ if self.env.config.rst_epilog:
+ data = data + '\n' + self.env.config.rst_epilog + '\n'
+ if self.env.config.rst_prolog:
+ data = self.env.config.rst_prolog + '\n' + data
+ return data
diff --git a/sphinx/quickstart.py b/sphinx/quickstart.py
index 9a60785..bbd32ae 100644
--- a/sphinx/quickstart.py
+++ b/sphinx/quickstart.py
@@ -9,6 +9,7 @@
:license: BSD, see LICENSE for details.
"""
from __future__ import print_function
+from __future__ import absolute_import
import re
import os
@@ -201,8 +202,8 @@ html_theme = 'alabaster'
# of the sidebar.
#html_logo = None
-# The name of an image file (within the static path) to use as favicon of the
-# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
+# The name of an image file (relative to this directory) to use as a favicon of
+# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
diff --git a/sphinx/search/__init__.py b/sphinx/search/__init__.py
index 06b8351..e4b3169 100644
--- a/sphinx/search/__init__.py
+++ b/sphinx/search/__init__.py
@@ -16,6 +16,7 @@ from docutils.nodes import raw, comment, title, Text, NodeVisitor, SkipNode
from os import path
from sphinx.util import jsdump, rpartition
+from sphinx.util.pycompat import htmlescape
class SearchLanguage(object):
@@ -283,6 +284,7 @@ class IndexBuilder(object):
continue
if prio < 0:
continue
+ fullname = htmlescape(fullname)
prefix, name = rpartition(fullname, '.')
pdict = rv.setdefault(prefix, {})
try:
diff --git a/sphinx/themes/agogo/static/agogo.css_t b/sphinx/themes/agogo/static/agogo.css_t
index 26df9d6..f3c8d67 100644
--- a/sphinx/themes/agogo/static/agogo.css_t
+++ b/sphinx/themes/agogo/static/agogo.css_t
@@ -507,3 +507,13 @@ div.code-block-caption {
padding: 2px 5px;
font-size: small;
}
+
+/* -- math display ---------------------------------------------------------- */
+
+div.body div.math p {
+ text-align: center;
+}
+
+span.eqno {
+ float: right;
+}
diff --git a/sphinx/themes/haiku/static/haiku.css_t b/sphinx/themes/haiku/static/haiku.css_t
index 0c20fd5..4fc1501 100644
--- a/sphinx/themes/haiku/static/haiku.css_t
+++ b/sphinx/themes/haiku/static/haiku.css_t
@@ -369,3 +369,8 @@ div.viewcode-block:target {
margin: -1px -10px;
padding: 0 12px;
}
+
+/* math display */
+div.math p {
+ text-align: center;
+}
diff --git a/sphinx/themes/scrolls/static/scrolls.css_t b/sphinx/themes/scrolls/static/scrolls.css_t
index 83752c9..12bb775 100644
--- a/sphinx/themes/scrolls/static/scrolls.css_t
+++ b/sphinx/themes/scrolls/static/scrolls.css_t
@@ -471,3 +471,13 @@ div.figure p.caption span.caption-number {
div.figure p.caption span.caption-text {
}
+
+/* math display */
+
+div.math p {
+ text-align: center;
+}
+
+span.eqno {
+ float: right;
+}
diff --git a/sphinx/themes/traditional/static/traditional.css_t b/sphinx/themes/traditional/static/traditional.css_t
index b98de22..1e1127e 100644
--- a/sphinx/themes/traditional/static/traditional.css_t
+++ b/sphinx/themes/traditional/static/traditional.css_t
@@ -736,3 +736,13 @@ div.figure p.caption span.caption-number {
div.figure p.caption span.caption-text {
}
+
+/* :::: MATH DISPLAY :::: */
+
+div.body div.math p {
+ text-align: center;
+}
+
+span.eqno {
+ float: right;
+}
diff --git a/sphinx/transforms.py b/sphinx/transforms.py
index 4619449..bfae7f8 100644
--- a/sphinx/transforms.py
+++ b/sphinx/transforms.py
@@ -12,8 +12,8 @@
from os import path
from docutils import nodes
-from docutils.utils import new_document, relative_path
-from docutils.parsers.rst import Parser as RSTParser
+from docutils.io import StringInput
+from docutils.utils import relative_path
from docutils.transforms import Transform
from docutils.transforms.parts import ContentsFilter
@@ -202,21 +202,33 @@ class ExtraTranslatableNodes(Transform):
node['translatable'] = True
-class CustomLocaleReporter(object):
- """
- Replacer for document.reporter.get_source_and_line method.
+def publish_msgstr(source, source_path, source_line, config, settings):
+ """Publish msgstr (single line) into docutils document
- reST text lines for translation do not have the original source line number.
- This class provides the correct line numbers when reporting.
+ :param unicode source: source text
+ :param unicode source_path: source path for warning indication
+ :param source_line: source line for warning indication
+ :param sphinx.config.Config config: sphinx config
+ :param docutils.frontend.Values settings: docutils settings
+ :return: document
+ :rtype: docutils.nodes.document
"""
- def __init__(self, source, line):
- self.source, self.line = source, line
-
- def set_reporter(self, document):
- document.reporter.get_source_and_line = self.get_source_and_line
-
- def get_source_and_line(self, lineno=None):
- return self.source, self.line
+ from sphinx.io import SphinxI18nReader
+ reader = SphinxI18nReader(
+ parsers=config.source_parsers,
+ parser_name='restructuredtext', # default parser
+ )
+ reader.set_lineno_for_reporter(source_line)
+ doc = reader.read(
+ source=StringInput(source=source, source_path=source_path),
+ parser=reader.parser,
+ settings=settings,
+ )
+ try:
+ doc = doc[0]
+ except IndexError: # empty node
+ pass
+ return doc
class Locale(Transform):
@@ -244,8 +256,6 @@ class Locale(Transform):
if not has_catalog:
return
- parser = RSTParser()
-
# phase1: replace reference ids with translated names
for node, msg in extract_messages(self.document):
msgstr = catalog.gettext(msg)
@@ -267,13 +277,7 @@ class Locale(Transform):
if isinstance(node, LITERAL_TYPE_NODES):
msgstr = '::\n\n' + indent(msgstr, ' '*3)
- patch = new_document(source, settings)
- CustomLocaleReporter(node.source, node.line).set_reporter(patch)
- parser.parse(msgstr, patch)
- try:
- patch = patch[0]
- except IndexError: # empty node
- pass
+ patch = publish_msgstr(msgstr, source, node.line, env.config, settings)
# XXX doctest and other block markup
if not isinstance(patch, nodes.paragraph):
continue # skip for now
@@ -390,13 +394,7 @@ class Locale(Transform):
if isinstance(node, LITERAL_TYPE_NODES):
msgstr = '::\n\n' + indent(msgstr, ' '*3)
- patch = new_document(source, settings)
- CustomLocaleReporter(node.source, node.line).set_reporter(patch)
- parser.parse(msgstr, patch)
- try:
- patch = patch[0]
- except IndexError: # empty node
- pass
+ patch = publish_msgstr(msgstr, source, node.line, env.config, settings)
# XXX doctest and other block markup
if not isinstance(
patch,
diff --git a/sphinx/util/nodes.py b/sphinx/util/nodes.py
index f8d2d0a..ccea957 100644
--- a/sphinx/util/nodes.py
+++ b/sphinx/util/nodes.py
@@ -141,9 +141,10 @@ def find_source_node(node):
return pnode.source
-def traverse_parent(node):
+def traverse_parent(node, cls=None):
while node:
- yield node
+ if cls is None or isinstance(node, cls):
+ yield node
node = node.parent
diff --git a/sphinx/writers/html.py b/sphinx/writers/html.py
index d647898..defb04c 100644
--- a/sphinx/writers/html.py
+++ b/sphinx/writers/html.py
@@ -442,7 +442,7 @@ class HTMLTranslator(BaseTranslator):
def visit_download_reference(self, node):
if node.hasattr('filename'):
self.body.append(
- '<a class="reference download internal" href="%s">' %
+ '<a class="reference download internal" href="%s" download="">' %
posixpath.join(self.builder.dlpath, node['filename']))
self.context.append('</a>')
else:
diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py
index 21ab154..e187ae3 100644
--- a/sphinx/writers/latex.py
+++ b/sphinx/writers/latex.py
@@ -25,7 +25,7 @@ from sphinx import highlighting
from sphinx.errors import SphinxError
from sphinx.locale import admonitionlabels, _
from sphinx.util import split_into
-from sphinx.util.nodes import clean_astext
+from sphinx.util.nodes import clean_astext, traverse_parent
from sphinx.util.osutil import ustrftime
from sphinx.util.texescape import tex_escape_map, tex_replace_map
from sphinx.util.smartypants import educate_quotes_latex
@@ -37,6 +37,7 @@ HEADER = r'''%% Generated by Sphinx.
%(utf8extra)s
%(cmappkg)s
%(fontenc)s
+%(amsfonts)s
%(babel)s
%(fontpkg)s
%(fncychap)s
@@ -159,11 +160,15 @@ class ShowUrlsTransform(object):
if node.astext() != uri:
index = node.parent.index(node)
if show_urls == 'footnote':
- footnote_nodes = self.create_footnote(uri)
- for i, fn in enumerate(footnote_nodes):
- node.parent.insert(index + i + 1, fn)
-
- self.expanded = True
+ if list(traverse_parent(node, nodes.topic)):
+ # should not expand references in topics
+ pass
+ else:
+ footnote_nodes = self.create_footnote(uri)
+ for i, fn in enumerate(footnote_nodes):
+ node.parent.insert(index + i + 1, fn)
+
+ self.expanded = True
else: # all other true values (b/w compat)
textnode = nodes.Text(" (%s)" % uri)
node.parent.insert(index + 1, textnode)
@@ -195,9 +200,14 @@ class ShowUrlsTransform(object):
def is_auto_footnote(node):
return isinstance(node, nodes.footnote) and node.get('auto')
- def footnote_ref_by(ids):
+ def footnote_ref_by(node):
+ ids = node['ids']
+ parent = list(traverse_parent(node, (nodes.document, addnodes.start_of_file)))[0]
+
def is_footnote_ref(node):
- return isinstance(node, nodes.footnote_reference) and ids[0] == node['refid']
+ return (isinstance(node, nodes.footnote_reference) and
+ ids[0] == node['refid'] and
+ parent in list(traverse_parent(node)))
return is_footnote_ref
@@ -216,7 +226,7 @@ class ShowUrlsTransform(object):
footnote['names'].remove(old_label)
footnote['names'].append(label)
- for footnote_ref in self.document.traverse(footnote_ref_by(footnote['ids'])):
+ for footnote_ref in self.document.traverse(footnote_ref_by(footnote)):
footnote_ref.remove(footnote_ref[0])
footnote_ref += nodes.Text(label)
@@ -249,6 +259,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
'utf8extra': '\\DeclareUnicodeCharacter{00A0}{\\nobreakspace}',
'cmappkg': '\\usepackage{cmap}',
'fontenc': '\\usepackage[T1]{fontenc}',
+ 'amsfonts': '',
'babel': '\\usepackage{babel}',
'fontpkg': '\\usepackage{times}',
'fncychap': '\\usepackage[Bjarne]{fncychap}',
@@ -346,11 +357,6 @@ class LaTeXTranslator(nodes.NodeVisitor):
return '\\usepackage{%s}' % (packagename,)
usepackages = (declare_package(*p) for p in builder.usepackages)
self.elements['usepackages'] += "\n".join(usepackages)
- if getattr(document.settings, 'contentsname', None):
- self.elements['contentsname'] = \
- self.babel_renewcommand(builder, '\\contentsname',
- document.settings.contentsname)
- self.elements['numfig_format'] = self.generate_numfig_format(builder)
# allow the user to override them all
self.elements.update(builder.config.latex_elements)
if self.elements['extraclassoptions']:
@@ -363,6 +369,11 @@ class LaTeXTranslator(nodes.NodeVisitor):
else:
self.elements['tocdepth'] = ('\\setcounter{tocdepth}{%d}' %
(document['tocdepth'] - 1))
+ if getattr(document.settings, 'contentsname', None):
+ self.elements['contentsname'] = \
+ self.babel_renewcommand(builder, '\\contentsname',
+ document.settings.contentsname)
+ self.elements['numfig_format'] = self.generate_numfig_format(builder)
self.highlighter = highlighting.PygmentsBridge(
'latex',
diff --git a/tests/roots/test-footnotes/bar.rst b/tests/roots/test-footnotes/bar.rst
new file mode 100644
index 0000000..660c663
--- /dev/null
+++ b/tests/roots/test-footnotes/bar.rst
@@ -0,0 +1,6 @@
... 230 lines suppressed ...
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/sphinx.git
More information about the Python-modules-commits
mailing list