mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
ext: pep8 fixes
This commit is contained in:
parent
ba9dcaac51
commit
b5c2279e05
@ -62,7 +62,9 @@ class DefDict(dict):
|
|||||||
return True
|
return True
|
||||||
__nonzero__ = __bool__ # for python2 compatibility
|
__nonzero__ = __bool__ # for python2 compatibility
|
||||||
|
|
||||||
identity = lambda x: x
|
|
||||||
|
def identity(x):
|
||||||
|
return x
|
||||||
|
|
||||||
|
|
||||||
class Options(dict):
|
class Options(dict):
|
||||||
@ -1311,9 +1313,9 @@ class AttributeDocumenter(DocstringStripSignatureMixin, ClassLevelDocumenter):
|
|||||||
isinstance(member, cls.method_types) and not \
|
isinstance(member, cls.method_types) and not \
|
||||||
type(member).__name__ in ("type", "method_descriptor",
|
type(member).__name__ in ("type", "method_descriptor",
|
||||||
"instancemethod")
|
"instancemethod")
|
||||||
return isdatadesc or (not isinstance(parent, ModuleDocumenter)
|
return isdatadesc or (not isinstance(parent, ModuleDocumenter) and
|
||||||
and not inspect.isroutine(member)
|
not inspect.isroutine(member) and
|
||||||
and not isinstance(member, class_types))
|
not isinstance(member, class_types))
|
||||||
|
|
||||||
def document_members(self, all_members=False):
|
def document_members(self, all_members=False):
|
||||||
pass
|
pass
|
||||||
|
@ -77,18 +77,20 @@ from sphinx.ext.autodoc import Options
|
|||||||
class autosummary_toc(nodes.comment):
|
class autosummary_toc(nodes.comment):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def process_autosummary_toc(app, doctree):
|
def process_autosummary_toc(app, doctree):
|
||||||
"""Insert items described in autosummary:: to the TOC tree, but do
|
"""Insert items described in autosummary:: to the TOC tree, but do
|
||||||
not generate the toctree:: list.
|
not generate the toctree:: list.
|
||||||
"""
|
"""
|
||||||
env = app.builder.env
|
env = app.builder.env
|
||||||
crawled = {}
|
crawled = {}
|
||||||
|
|
||||||
def crawl_toc(node, depth=1):
|
def crawl_toc(node, depth=1):
|
||||||
crawled[node] = True
|
crawled[node] = True
|
||||||
for j, subnode in enumerate(node):
|
for j, subnode in enumerate(node):
|
||||||
try:
|
try:
|
||||||
if (isinstance(subnode, autosummary_toc)
|
if (isinstance(subnode, autosummary_toc) and
|
||||||
and isinstance(subnode[0], addnodes.toctree)):
|
isinstance(subnode[0], addnodes.toctree)):
|
||||||
env.note_toctree(env.docname, subnode[0])
|
env.note_toctree(env.docname, subnode[0])
|
||||||
continue
|
continue
|
||||||
except IndexError:
|
except IndexError:
|
||||||
@ -99,10 +101,12 @@ def process_autosummary_toc(app, doctree):
|
|||||||
crawl_toc(subnode, depth+1)
|
crawl_toc(subnode, depth+1)
|
||||||
crawl_toc(doctree)
|
crawl_toc(doctree)
|
||||||
|
|
||||||
|
|
||||||
def autosummary_toc_visit_html(self, node):
|
def autosummary_toc_visit_html(self, node):
|
||||||
"""Hide autosummary toctree list in HTML output."""
|
"""Hide autosummary toctree list in HTML output."""
|
||||||
raise nodes.SkipNode
|
raise nodes.SkipNode
|
||||||
|
|
||||||
|
|
||||||
def autosummary_noop(self, node):
|
def autosummary_noop(self, node):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -112,6 +116,7 @@ def autosummary_noop(self, node):
|
|||||||
class autosummary_table(nodes.comment):
|
class autosummary_table(nodes.comment):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def autosummary_table_visit_html(self, node):
|
def autosummary_table_visit_html(self, node):
|
||||||
"""Make the first column of the table non-breaking."""
|
"""Make the first column of the table non-breaking."""
|
||||||
try:
|
try:
|
||||||
@ -134,6 +139,7 @@ class FakeDirective:
|
|||||||
env = {}
|
env = {}
|
||||||
genopt = Options()
|
genopt = Options()
|
||||||
|
|
||||||
|
|
||||||
def get_documenter(obj, parent):
|
def get_documenter(obj, parent):
|
||||||
"""Get an autodoc.Documenter class suitable for documenting the given
|
"""Get an autodoc.Documenter class suitable for documenting the given
|
||||||
object.
|
object.
|
||||||
@ -143,7 +149,7 @@ def get_documenter(obj, parent):
|
|||||||
belongs to.
|
belongs to.
|
||||||
"""
|
"""
|
||||||
from sphinx.ext.autodoc import AutoDirective, DataDocumenter, \
|
from sphinx.ext.autodoc import AutoDirective, DataDocumenter, \
|
||||||
ModuleDocumenter
|
ModuleDocumenter
|
||||||
|
|
||||||
if inspect.ismodule(obj):
|
if inspect.ismodule(obj):
|
||||||
# ModuleDocumenter.can_document_member always returns False
|
# ModuleDocumenter.can_document_member always returns False
|
||||||
@ -219,7 +225,7 @@ class Autosummary(Directive):
|
|||||||
|
|
||||||
tocnode = addnodes.toctree()
|
tocnode = addnodes.toctree()
|
||||||
tocnode['includefiles'] = docnames
|
tocnode['includefiles'] = docnames
|
||||||
tocnode['entries'] = [(None, docname) for docname in docnames]
|
tocnode['entries'] = [(None, docn) for docn in docnames]
|
||||||
tocnode['maxdepth'] = -1
|
tocnode['maxdepth'] = -1
|
||||||
tocnode['glob'] = None
|
tocnode['glob'] = None
|
||||||
|
|
||||||
@ -276,7 +282,7 @@ class Autosummary(Directive):
|
|||||||
# try to also get a source code analyzer for attribute docs
|
# try to also get a source code analyzer for attribute docs
|
||||||
try:
|
try:
|
||||||
documenter.analyzer = ModuleAnalyzer.for_module(
|
documenter.analyzer = ModuleAnalyzer.for_module(
|
||||||
documenter.get_real_modname())
|
documenter.get_real_modname())
|
||||||
# parse right now, to get PycodeErrors on parsing (results will
|
# parse right now, to get PycodeErrors on parsing (results will
|
||||||
# be cached anyway)
|
# be cached anyway)
|
||||||
documenter.analyzer.find_attr_docs()
|
documenter.analyzer.find_attr_docs()
|
||||||
@ -369,6 +375,7 @@ class Autosummary(Directive):
|
|||||||
|
|
||||||
return [table_spec, table]
|
return [table_spec, table]
|
||||||
|
|
||||||
|
|
||||||
def mangle_signature(sig, max_chars=30):
|
def mangle_signature(sig, max_chars=30):
|
||||||
"""Reformat a function signature to a more compact form."""
|
"""Reformat a function signature to a more compact form."""
|
||||||
s = re.sub(r"^\((.*)\)$", r"\1", sig).strip()
|
s = re.sub(r"^\((.*)\)$", r"\1", sig).strip()
|
||||||
@ -404,6 +411,7 @@ def mangle_signature(sig, max_chars=30):
|
|||||||
|
|
||||||
return u"(%s)" % sig
|
return u"(%s)" % sig
|
||||||
|
|
||||||
|
|
||||||
def limited_join(sep, items, max_chars=30, overflow_marker="..."):
|
def limited_join(sep, items, max_chars=30, overflow_marker="..."):
|
||||||
"""Join a number of strings to one, limiting the length to *max_chars*.
|
"""Join a number of strings to one, limiting the length to *max_chars*.
|
||||||
|
|
||||||
@ -427,6 +435,7 @@ def limited_join(sep, items, max_chars=30, overflow_marker="..."):
|
|||||||
|
|
||||||
return sep.join(list(items[:n_items]) + [overflow_marker])
|
return sep.join(list(items[:n_items]) + [overflow_marker])
|
||||||
|
|
||||||
|
|
||||||
# -- Importing items -----------------------------------------------------------
|
# -- Importing items -----------------------------------------------------------
|
||||||
|
|
||||||
def get_import_prefixes_from_env(env):
|
def get_import_prefixes_from_env(env):
|
||||||
@ -449,6 +458,7 @@ def get_import_prefixes_from_env(env):
|
|||||||
|
|
||||||
return prefixes
|
return prefixes
|
||||||
|
|
||||||
|
|
||||||
def import_by_name(name, prefixes=[None]):
|
def import_by_name(name, prefixes=[None]):
|
||||||
"""Import a Python object that has the given *name*, under one of the
|
"""Import a Python object that has the given *name*, under one of the
|
||||||
*prefixes*. The first name that succeeds is used.
|
*prefixes*. The first name that succeeds is used.
|
||||||
@ -466,6 +476,7 @@ def import_by_name(name, prefixes=[None]):
|
|||||||
tried.append(prefixed_name)
|
tried.append(prefixed_name)
|
||||||
raise ImportError('no module named %s' % ' or '.join(tried))
|
raise ImportError('no module named %s' % ' or '.join(tried))
|
||||||
|
|
||||||
|
|
||||||
def _import_by_name(name):
|
def _import_by_name(name):
|
||||||
"""Import a Python object given its full name."""
|
"""Import a Python object given its full name."""
|
||||||
try:
|
try:
|
||||||
|
@ -71,12 +71,15 @@ def main(argv=sys.argv):
|
|||||||
"." + options.suffix,
|
"." + options.suffix,
|
||||||
template_dir=options.templates)
|
template_dir=options.templates)
|
||||||
|
|
||||||
|
|
||||||
def _simple_info(msg):
|
def _simple_info(msg):
|
||||||
print(msg)
|
print(msg)
|
||||||
|
|
||||||
|
|
||||||
def _simple_warn(msg):
|
def _simple_warn(msg):
|
||||||
print('WARNING: ' + msg, file=sys.stderr)
|
print('WARNING: ' + msg, file=sys.stderr)
|
||||||
|
|
||||||
|
|
||||||
# -- Generating output ---------------------------------------------------------
|
# -- Generating output ---------------------------------------------------------
|
||||||
|
|
||||||
def generate_autosummary_docs(sources, output_dir=None, suffix='.rst',
|
def generate_autosummary_docs(sources, output_dir=None, suffix='.rst',
|
||||||
@ -169,17 +172,17 @@ def generate_autosummary_docs(sources, output_dir=None, suffix='.rst',
|
|||||||
if doc.objtype == 'module':
|
if doc.objtype == 'module':
|
||||||
ns['members'] = dir(obj)
|
ns['members'] = dir(obj)
|
||||||
ns['functions'], ns['all_functions'] = \
|
ns['functions'], ns['all_functions'] = \
|
||||||
get_members(obj, 'function')
|
get_members(obj, 'function')
|
||||||
ns['classes'], ns['all_classes'] = \
|
ns['classes'], ns['all_classes'] = \
|
||||||
get_members(obj, 'class')
|
get_members(obj, 'class')
|
||||||
ns['exceptions'], ns['all_exceptions'] = \
|
ns['exceptions'], ns['all_exceptions'] = \
|
||||||
get_members(obj, 'exception')
|
get_members(obj, 'exception')
|
||||||
elif doc.objtype == 'class':
|
elif doc.objtype == 'class':
|
||||||
ns['members'] = dir(obj)
|
ns['members'] = dir(obj)
|
||||||
ns['methods'], ns['all_methods'] = \
|
ns['methods'], ns['all_methods'] = \
|
||||||
get_members(obj, 'method', ['__init__'])
|
get_members(obj, 'method', ['__init__'])
|
||||||
ns['attributes'], ns['all_attributes'] = \
|
ns['attributes'], ns['all_attributes'] = \
|
||||||
get_members(obj, 'attribute')
|
get_members(obj, 'attribute')
|
||||||
|
|
||||||
parts = name.split('.')
|
parts = name.split('.')
|
||||||
if doc.objtype in ('method', 'attribute'):
|
if doc.objtype in ('method', 'attribute'):
|
||||||
@ -289,7 +292,7 @@ def find_autosummary_in_lines(lines, module=None, filename=None):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
if line.strip().startswith(':'):
|
if line.strip().startswith(':'):
|
||||||
continue # skip options
|
continue # skip options
|
||||||
|
|
||||||
m = autosummary_item_re.match(line)
|
m = autosummary_item_re.match(line)
|
||||||
if m:
|
if m:
|
||||||
@ -297,7 +300,7 @@ def find_autosummary_in_lines(lines, module=None, filename=None):
|
|||||||
if name.startswith('~'):
|
if name.startswith('~'):
|
||||||
name = name[1:]
|
name = name[1:]
|
||||||
if current_module and \
|
if current_module and \
|
||||||
not name.startswith(current_module + '.'):
|
not name.startswith(current_module + '.'):
|
||||||
name = "%s.%s" % (current_module, name)
|
name = "%s.%s" % (current_module, name)
|
||||||
documented.append((name, toctree, template))
|
documented.append((name, toctree, template))
|
||||||
continue
|
continue
|
||||||
|
@ -27,6 +27,7 @@ def write_header(f, text, char='-'):
|
|||||||
f.write(text + '\n')
|
f.write(text + '\n')
|
||||||
f.write(char * len(text) + '\n')
|
f.write(char * len(text) + '\n')
|
||||||
|
|
||||||
|
|
||||||
def compile_regex_list(name, exps, warnfunc):
|
def compile_regex_list(name, exps, warnfunc):
|
||||||
lst = []
|
lst = []
|
||||||
for exp in exps:
|
for exp in exps:
|
||||||
@ -231,7 +232,7 @@ class CoverageBuilder(Builder):
|
|||||||
if undoc['classes']:
|
if undoc['classes']:
|
||||||
op.write('Classes:\n')
|
op.write('Classes:\n')
|
||||||
for name, methods in sorted(
|
for name, methods in sorted(
|
||||||
iteritems(undoc['classes'])):
|
iteritems(undoc['classes'])):
|
||||||
if not methods:
|
if not methods:
|
||||||
op.write(' * %s\n' % name)
|
op.write(' * %s\n' % name)
|
||||||
else:
|
else:
|
||||||
|
@ -15,8 +15,6 @@ import sys
|
|||||||
import time
|
import time
|
||||||
import codecs
|
import codecs
|
||||||
from os import path
|
from os import path
|
||||||
# circumvent relative import
|
|
||||||
doctest = __import__('doctest')
|
|
||||||
|
|
||||||
from six import itervalues, StringIO, binary_type
|
from six import itervalues, StringIO, binary_type
|
||||||
from docutils import nodes
|
from docutils import nodes
|
||||||
@ -29,6 +27,9 @@ from sphinx.util.nodes import set_source_info
|
|||||||
from sphinx.util.compat import Directive
|
from sphinx.util.compat import Directive
|
||||||
from sphinx.util.console import bold
|
from sphinx.util.console import bold
|
||||||
|
|
||||||
|
# circumvent relative import
|
||||||
|
doctest = __import__('doctest')
|
||||||
|
|
||||||
blankline_re = re.compile(r'^\s*<BLANKLINE>', re.MULTILINE)
|
blankline_re = re.compile(r'^\s*<BLANKLINE>', re.MULTILINE)
|
||||||
doctestopt_re = re.compile(r'#\s*doctest:.+$', re.MULTILINE)
|
doctestopt_re = re.compile(r'#\s*doctest:.+$', re.MULTILINE)
|
||||||
|
|
||||||
@ -296,8 +297,8 @@ Doctest summary
|
|||||||
|
|
||||||
if self.config.doctest_test_doctest_blocks:
|
if self.config.doctest_test_doctest_blocks:
|
||||||
def condition(node):
|
def condition(node):
|
||||||
return (isinstance(node, (nodes.literal_block, nodes.comment))
|
return (isinstance(node, (nodes.literal_block, nodes.comment)) and
|
||||||
and 'testnodetype' in node) or \
|
'testnodetype' in node) or \
|
||||||
isinstance(node, nodes.doctest_block)
|
isinstance(node, nodes.doctest_block)
|
||||||
else:
|
else:
|
||||||
def condition(node):
|
def condition(node):
|
||||||
|
@ -52,10 +52,12 @@ def make_link_role(base_url, prefix):
|
|||||||
return [pnode], []
|
return [pnode], []
|
||||||
return role
|
return role
|
||||||
|
|
||||||
|
|
||||||
def setup_link_roles(app):
|
def setup_link_roles(app):
|
||||||
for name, (base_url, prefix) in iteritems(app.config.extlinks):
|
for name, (base_url, prefix) in iteritems(app.config.extlinks):
|
||||||
app.add_role(name, make_link_role(base_url, prefix))
|
app.add_role(name, make_link_role(base_url, prefix))
|
||||||
|
|
||||||
|
|
||||||
def setup(app):
|
def setup(app):
|
||||||
app.add_config_value('extlinks', {}, 'env')
|
app.add_config_value('extlinks', {}, 'env')
|
||||||
app.connect('builder-inited', setup_link_roles)
|
app.connect('builder-inited', setup_link_roles)
|
||||||
|
@ -141,9 +141,8 @@ class GraphvizSimple(Directive):
|
|||||||
def render_dot(self, code, options, format, prefix='graphviz'):
|
def render_dot(self, code, options, format, prefix='graphviz'):
|
||||||
"""Render graphviz code into a PNG or PDF output file."""
|
"""Render graphviz code into a PNG or PDF output file."""
|
||||||
hashkey = (code + str(options) +
|
hashkey = (code + str(options) +
|
||||||
str(self.builder.config.graphviz_dot) +
|
str(self.builder.config.graphviz_dot) +
|
||||||
str(self.builder.config.graphviz_dot_args)
|
str(self.builder.config.graphviz_dot_args)).encode('utf-8')
|
||||||
).encode('utf-8')
|
|
||||||
|
|
||||||
fname = '%s-%s.%s' % (prefix, sha1(hashkey).hexdigest(), format)
|
fname = '%s-%s.%s' % (prefix, sha1(hashkey).hexdigest(), format)
|
||||||
relfn = posixpath.join(self.builder.imgpath, fname)
|
relfn = posixpath.join(self.builder.imgpath, fname)
|
||||||
@ -284,6 +283,7 @@ def render_dot_texinfo(self, node, code, options, prefix='graphviz'):
|
|||||||
self.body.append('@image{%s,,,[graphviz],png}\n' % fname[:-4])
|
self.body.append('@image{%s,,,[graphviz],png}\n' % fname[:-4])
|
||||||
raise nodes.SkipNode
|
raise nodes.SkipNode
|
||||||
|
|
||||||
|
|
||||||
def texinfo_visit_graphviz(self, node):
|
def texinfo_visit_graphviz(self, node):
|
||||||
render_dot_texinfo(self, node, node['code'], node['options'])
|
render_dot_texinfo(self, node, node['code'], node['options'])
|
||||||
|
|
||||||
|
@ -27,7 +27,8 @@ from sphinx.util.nodes import set_source_info
|
|||||||
from sphinx.util.compat import Directive
|
from sphinx.util.compat import Directive
|
||||||
|
|
||||||
|
|
||||||
class ifconfig(nodes.Element): pass
|
class ifconfig(nodes.Element):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class IfConfig(Directive):
|
class IfConfig(Directive):
|
||||||
|
@ -109,10 +109,10 @@ def read_inventory_v2(f, uri, join, bufsize=16*1024):
|
|||||||
continue
|
continue
|
||||||
name, type, prio, location, dispname = m.groups()
|
name, type, prio, location, dispname = m.groups()
|
||||||
if type == 'py:module' and type in invdata and \
|
if type == 'py:module' and type in invdata and \
|
||||||
name in invdata[type]: # due to a bug in 1.1 and below,
|
name in invdata[type]: # due to a bug in 1.1 and below,
|
||||||
# two inventory entries are created
|
# two inventory entries are created
|
||||||
# for Python modules, and the first
|
# for Python modules, and the first
|
||||||
# one is correct
|
# one is correct
|
||||||
continue
|
continue
|
||||||
if location.endswith(u'$'):
|
if location.endswith(u'$'):
|
||||||
location = location[:-1] + name
|
location = location[:-1] + name
|
||||||
@ -212,7 +212,7 @@ def load_mappings(app):
|
|||||||
cached_vals = list(cache.values())
|
cached_vals = list(cache.values())
|
||||||
named_vals = sorted(v for v in cached_vals if v[0])
|
named_vals = sorted(v for v in cached_vals if v[0])
|
||||||
unnamed_vals = [v for v in cached_vals if not v[0]]
|
unnamed_vals = [v for v in cached_vals if not v[0]]
|
||||||
for name, _, invdata in named_vals + unnamed_vals:
|
for name, _x, invdata in named_vals + unnamed_vals:
|
||||||
if name:
|
if name:
|
||||||
env.intersphinx_named_inventory[name] = invdata
|
env.intersphinx_named_inventory[name] = invdata
|
||||||
for type, objects in iteritems(invdata):
|
for type, objects in iteritems(invdata):
|
||||||
|
@ -22,6 +22,7 @@ def html_visit_math(self, node):
|
|||||||
self.body.append(self.encode(node['latex']) + '</span>')
|
self.body.append(self.encode(node['latex']) + '</span>')
|
||||||
raise nodes.SkipNode
|
raise nodes.SkipNode
|
||||||
|
|
||||||
|
|
||||||
def html_visit_displaymath(self, node):
|
def html_visit_displaymath(self, node):
|
||||||
if node['nowrap']:
|
if node['nowrap']:
|
||||||
self.body.append(self.starttag(node, 'div', CLASS='math'))
|
self.body.append(self.starttag(node, 'div', CLASS='math'))
|
||||||
@ -46,6 +47,7 @@ def html_visit_displaymath(self, node):
|
|||||||
self.body.append('</div>\n')
|
self.body.append('</div>\n')
|
||||||
raise nodes.SkipNode
|
raise nodes.SkipNode
|
||||||
|
|
||||||
|
|
||||||
def builder_inited(app):
|
def builder_inited(app):
|
||||||
if not app.config.jsmath_path:
|
if not app.config.jsmath_path:
|
||||||
raise ExtensionError('jsmath_path config value must be set for the '
|
raise ExtensionError('jsmath_path config value must be set for the '
|
||||||
|
@ -19,9 +19,11 @@ from sphinx.util.compat import Directive
|
|||||||
class math(nodes.Inline, nodes.TextElement):
|
class math(nodes.Inline, nodes.TextElement):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class displaymath(nodes.Part, nodes.Element):
|
class displaymath(nodes.Part, nodes.Element):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class eqref(nodes.Inline, nodes.TextElement):
|
class eqref(nodes.Inline, nodes.TextElement):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -46,6 +48,7 @@ def math_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
|
|||||||
latex = utils.unescape(text, restore_backslashes=True)
|
latex = utils.unescape(text, restore_backslashes=True)
|
||||||
return [math(latex=latex)], []
|
return [math(latex=latex)], []
|
||||||
|
|
||||||
|
|
||||||
def eq_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
|
def eq_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
|
||||||
text = utils.unescape(text)
|
text = utils.unescape(text)
|
||||||
node = eqref('(?)', '(?)', target=text)
|
node = eqref('(?)', '(?)', target=text)
|
||||||
@ -91,6 +94,7 @@ def latex_visit_math(self, node):
|
|||||||
self.body.append('\\(' + node['latex'] + '\\)')
|
self.body.append('\\(' + node['latex'] + '\\)')
|
||||||
raise nodes.SkipNode
|
raise nodes.SkipNode
|
||||||
|
|
||||||
|
|
||||||
def latex_visit_displaymath(self, node):
|
def latex_visit_displaymath(self, node):
|
||||||
if node['nowrap']:
|
if node['nowrap']:
|
||||||
self.body.append(node['latex'])
|
self.body.append(node['latex'])
|
||||||
@ -99,6 +103,7 @@ def latex_visit_displaymath(self, node):
|
|||||||
self.body.append(wrap_displaymath(node['latex'], label))
|
self.body.append(wrap_displaymath(node['latex'], label))
|
||||||
raise nodes.SkipNode
|
raise nodes.SkipNode
|
||||||
|
|
||||||
|
|
||||||
def latex_visit_eqref(self, node):
|
def latex_visit_eqref(self, node):
|
||||||
self.body.append('\\eqref{%s-%s}' % (node['docname'], node['target']))
|
self.body.append('\\eqref{%s-%s}' % (node['docname'], node['target']))
|
||||||
raise nodes.SkipNode
|
raise nodes.SkipNode
|
||||||
@ -108,12 +113,14 @@ def text_visit_math(self, node):
|
|||||||
self.add_text(node['latex'])
|
self.add_text(node['latex'])
|
||||||
raise nodes.SkipNode
|
raise nodes.SkipNode
|
||||||
|
|
||||||
|
|
||||||
def text_visit_displaymath(self, node):
|
def text_visit_displaymath(self, node):
|
||||||
self.new_state()
|
self.new_state()
|
||||||
self.add_text(node['latex'])
|
self.add_text(node['latex'])
|
||||||
self.end_state()
|
self.end_state()
|
||||||
raise nodes.SkipNode
|
raise nodes.SkipNode
|
||||||
|
|
||||||
|
|
||||||
def text_visit_eqref(self, node):
|
def text_visit_eqref(self, node):
|
||||||
self.add_text(node['target'])
|
self.add_text(node['target'])
|
||||||
raise nodes.SkipNode
|
raise nodes.SkipNode
|
||||||
@ -123,11 +130,15 @@ def man_visit_math(self, node):
|
|||||||
self.body.append(node['latex'])
|
self.body.append(node['latex'])
|
||||||
raise nodes.SkipNode
|
raise nodes.SkipNode
|
||||||
|
|
||||||
|
|
||||||
def man_visit_displaymath(self, node):
|
def man_visit_displaymath(self, node):
|
||||||
self.visit_centered(node)
|
self.visit_centered(node)
|
||||||
|
|
||||||
|
|
||||||
def man_depart_displaymath(self, node):
|
def man_depart_displaymath(self, node):
|
||||||
self.depart_centered(node)
|
self.depart_centered(node)
|
||||||
|
|
||||||
|
|
||||||
def man_visit_eqref(self, node):
|
def man_visit_eqref(self, node):
|
||||||
self.body.append(node['target'])
|
self.body.append(node['target'])
|
||||||
raise nodes.SkipNode
|
raise nodes.SkipNode
|
||||||
@ -137,14 +148,18 @@ def texinfo_visit_math(self, node):
|
|||||||
self.body.append('@math{' + self.escape_arg(node['latex']) + '}')
|
self.body.append('@math{' + self.escape_arg(node['latex']) + '}')
|
||||||
raise nodes.SkipNode
|
raise nodes.SkipNode
|
||||||
|
|
||||||
|
|
||||||
def texinfo_visit_displaymath(self, node):
|
def texinfo_visit_displaymath(self, node):
|
||||||
if node.get('label'):
|
if node.get('label'):
|
||||||
self.add_anchor(node['label'], node)
|
self.add_anchor(node['label'], node)
|
||||||
self.body.append('\n\n@example\n%s\n@end example\n\n' %
|
self.body.append('\n\n@example\n%s\n@end example\n\n' %
|
||||||
self.escape_arg(node['latex']))
|
self.escape_arg(node['latex']))
|
||||||
|
|
||||||
|
|
||||||
def texinfo_depart_displaymath(self, node):
|
def texinfo_depart_displaymath(self, node):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def texinfo_visit_eqref(self, node):
|
def texinfo_visit_eqref(self, node):
|
||||||
self.add_xref(node['docname'] + ':' + node['target'],
|
self.add_xref(node['docname'] + ':' + node['target'],
|
||||||
node['target'], node)
|
node['target'], node)
|
||||||
@ -154,6 +169,7 @@ def texinfo_visit_eqref(self, node):
|
|||||||
def html_visit_eqref(self, node):
|
def html_visit_eqref(self, node):
|
||||||
self.body.append('<a href="#equation-%s">' % node['target'])
|
self.body.append('<a href="#equation-%s">' % node['target'])
|
||||||
|
|
||||||
|
|
||||||
def html_depart_eqref(self, node):
|
def html_depart_eqref(self, node):
|
||||||
self.body.append('</a>')
|
self.body.append('</a>')
|
||||||
|
|
||||||
@ -177,23 +193,23 @@ def number_equations(app, doctree, docname):
|
|||||||
|
|
||||||
def setup_math(app, htmlinlinevisitors, htmldisplayvisitors):
|
def setup_math(app, htmlinlinevisitors, htmldisplayvisitors):
|
||||||
app.add_node(math,
|
app.add_node(math,
|
||||||
latex=(latex_visit_math, None),
|
latex=(latex_visit_math, None),
|
||||||
text=(text_visit_math, None),
|
text=(text_visit_math, None),
|
||||||
man=(man_visit_math, None),
|
man=(man_visit_math, None),
|
||||||
texinfo=(texinfo_visit_math, None),
|
texinfo=(texinfo_visit_math, None),
|
||||||
html=htmlinlinevisitors)
|
html=htmlinlinevisitors)
|
||||||
app.add_node(displaymath,
|
app.add_node(displaymath,
|
||||||
latex=(latex_visit_displaymath, None),
|
latex=(latex_visit_displaymath, None),
|
||||||
text=(text_visit_displaymath, None),
|
text=(text_visit_displaymath, None),
|
||||||
man=(man_visit_displaymath, man_depart_displaymath),
|
man=(man_visit_displaymath, man_depart_displaymath),
|
||||||
texinfo=(texinfo_visit_displaymath, texinfo_depart_displaymath),
|
texinfo=(texinfo_visit_displaymath, texinfo_depart_displaymath),
|
||||||
html=htmldisplayvisitors)
|
html=htmldisplayvisitors)
|
||||||
app.add_node(eqref,
|
app.add_node(eqref,
|
||||||
latex=(latex_visit_eqref, None),
|
latex=(latex_visit_eqref, None),
|
||||||
text=(text_visit_eqref, None),
|
text=(text_visit_eqref, None),
|
||||||
man=(man_visit_eqref, None),
|
man=(man_visit_eqref, None),
|
||||||
texinfo=(texinfo_visit_eqref, None),
|
texinfo=(texinfo_visit_eqref, None),
|
||||||
html=(html_visit_eqref, html_depart_eqref))
|
html=(html_visit_eqref, html_depart_eqref))
|
||||||
app.add_role('math', math_role)
|
app.add_role('math', math_role)
|
||||||
app.add_role('eq', eq_role)
|
app.add_role('eq', eq_role)
|
||||||
app.add_directive('math', MathDirective)
|
app.add_directive('math', MathDirective)
|
||||||
|
@ -25,6 +25,7 @@ def html_visit_math(self, node):
|
|||||||
self.builder.config.mathjax_inline[1] + '</span>')
|
self.builder.config.mathjax_inline[1] + '</span>')
|
||||||
raise nodes.SkipNode
|
raise nodes.SkipNode
|
||||||
|
|
||||||
|
|
||||||
def html_visit_displaymath(self, node):
|
def html_visit_displaymath(self, node):
|
||||||
self.body.append(self.starttag(node, 'div', CLASS='math'))
|
self.body.append(self.starttag(node, 'div', CLASS='math'))
|
||||||
if node['nowrap']:
|
if node['nowrap']:
|
||||||
@ -52,6 +53,7 @@ def html_visit_displaymath(self, node):
|
|||||||
self.body.append('</div>\n')
|
self.body.append('</div>\n')
|
||||||
raise nodes.SkipNode
|
raise nodes.SkipNode
|
||||||
|
|
||||||
|
|
||||||
def builder_inited(app):
|
def builder_inited(app):
|
||||||
if not app.config.mathjax_path:
|
if not app.config.mathjax_path:
|
||||||
raise ExtensionError('mathjax_path config value must be set for the '
|
raise ExtensionError('mathjax_path config value must be set for the '
|
||||||
|
@ -28,6 +28,7 @@ from sphinx.util.osutil import ensuredir, ENOENT, cd
|
|||||||
from sphinx.util.pycompat import sys_encoding
|
from sphinx.util.pycompat import sys_encoding
|
||||||
from sphinx.ext.mathbase import setup_math as mathbase_setup, wrap_displaymath
|
from sphinx.ext.mathbase import setup_math as mathbase_setup, wrap_displaymath
|
||||||
|
|
||||||
|
|
||||||
class MathExtError(SphinxError):
|
class MathExtError(SphinxError):
|
||||||
category = 'Math extension error'
|
category = 'Math extension error'
|
||||||
|
|
||||||
@ -67,6 +68,7 @@ DOC_BODY_PREVIEW = r'''
|
|||||||
|
|
||||||
depth_re = re.compile(br'\[\d+ depth=(-?\d+)\]')
|
depth_re = re.compile(br'\[\d+ depth=(-?\d+)\]')
|
||||||
|
|
||||||
|
|
||||||
def render_math(self, math):
|
def render_math(self, math):
|
||||||
"""Render the LaTeX math expression *math* using latex and dvipng.
|
"""Render the LaTeX math expression *math* using latex and dvipng.
|
||||||
|
|
||||||
@ -166,6 +168,7 @@ def render_math(self, math):
|
|||||||
|
|
||||||
return relfn, depth
|
return relfn, depth
|
||||||
|
|
||||||
|
|
||||||
def cleanup_tempdir(app, exc):
|
def cleanup_tempdir(app, exc):
|
||||||
if exc:
|
if exc:
|
||||||
return
|
return
|
||||||
@ -176,11 +179,13 @@ def cleanup_tempdir(app, exc):
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def get_tooltip(self, node):
|
def get_tooltip(self, node):
|
||||||
if self.builder.config.pngmath_add_tooltips:
|
if self.builder.config.pngmath_add_tooltips:
|
||||||
return ' alt="%s"' % self.encode(node['latex']).strip()
|
return ' alt="%s"' % self.encode(node['latex']).strip()
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
|
||||||
def html_visit_math(self, node):
|
def html_visit_math(self, node):
|
||||||
try:
|
try:
|
||||||
fname, depth = render_math(self, '$'+node['latex']+'$')
|
fname, depth = render_math(self, '$'+node['latex']+'$')
|
||||||
@ -202,6 +207,7 @@ def html_visit_math(self, node):
|
|||||||
self.body.append(c + '/>')
|
self.body.append(c + '/>')
|
||||||
raise nodes.SkipNode
|
raise nodes.SkipNode
|
||||||
|
|
||||||
|
|
||||||
def html_visit_displaymath(self, node):
|
def html_visit_displaymath(self, node):
|
||||||
if node['nowrap']:
|
if node['nowrap']:
|
||||||
latex = node['latex']
|
latex = node['latex']
|
||||||
@ -224,8 +230,8 @@ def html_visit_displaymath(self, node):
|
|||||||
self.body.append('<span class="math">%s</span></p>\n</div>' %
|
self.body.append('<span class="math">%s</span></p>\n</div>' %
|
||||||
self.encode(node['latex']).strip())
|
self.encode(node['latex']).strip())
|
||||||
else:
|
else:
|
||||||
self.body.append(('<img src="%s"' % fname) + get_tooltip(self, node)
|
self.body.append(('<img src="%s"' % fname) + get_tooltip(self, node) +
|
||||||
+ '/></p>\n</div>')
|
'/></p>\n</div>')
|
||||||
raise nodes.SkipNode
|
raise nodes.SkipNode
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,8 +20,13 @@ from sphinx.environment import NoUri
|
|||||||
from sphinx.util.nodes import set_source_info
|
from sphinx.util.nodes import set_source_info
|
||||||
from sphinx.util.compat import Directive, make_admonition
|
from sphinx.util.compat import Directive, make_admonition
|
||||||
|
|
||||||
class todo_node(nodes.Admonition, nodes.Element): pass
|
|
||||||
class todolist(nodes.General, nodes.Element): pass
|
class todo_node(nodes.Admonition, nodes.Element):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class todolist(nodes.General, nodes.Element):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Todo(Directive):
|
class Todo(Directive):
|
||||||
@ -112,7 +117,7 @@ def process_todo_nodes(app, doctree, fromdocname):
|
|||||||
para = nodes.paragraph(classes=['todo-source'])
|
para = nodes.paragraph(classes=['todo-source'])
|
||||||
description = _('(The <<original entry>> is located in '
|
description = _('(The <<original entry>> is located in '
|
||||||
' %s, line %d.)') % \
|
' %s, line %d.)') % \
|
||||||
(todo_info['source'], todo_info['lineno'])
|
(todo_info['source'], todo_info['lineno'])
|
||||||
desc1 = description[:description.find('<<')]
|
desc1 = description[:description.find('<<')]
|
||||||
desc2 = description[description.find('>>')+2:]
|
desc2 = description[description.find('>>')+2:]
|
||||||
para += nodes.Text(desc1, desc1)
|
para += nodes.Text(desc1, desc1)
|
||||||
@ -161,9 +166,11 @@ def merge_info(app, env, docnames, other):
|
|||||||
def visit_todo_node(self, node):
|
def visit_todo_node(self, node):
|
||||||
self.visit_admonition(node)
|
self.visit_admonition(node)
|
||||||
|
|
||||||
|
|
||||||
def depart_todo_node(self, node):
|
def depart_todo_node(self, node):
|
||||||
self.depart_admonition(node)
|
self.depart_admonition(node)
|
||||||
|
|
||||||
|
|
||||||
def setup(app):
|
def setup(app):
|
||||||
app.add_config_value('todo_include_todos', False, 'html')
|
app.add_config_value('todo_include_todos', False, 'html')
|
||||||
|
|
||||||
|
@ -155,8 +155,8 @@ def collect_pages(app):
|
|||||||
backlink = urito(pagename, docname) + '#' + refname + '.' + name
|
backlink = urito(pagename, docname) + '#' + refname + '.' + name
|
||||||
lines[start] = (
|
lines[start] = (
|
||||||
'<div class="viewcode-block" id="%s"><a class="viewcode-back" '
|
'<div class="viewcode-block" id="%s"><a class="viewcode-back" '
|
||||||
'href="%s">%s</a>' % (name, backlink, _('[docs]'))
|
'href="%s">%s</a>' % (name, backlink, _('[docs]')) +
|
||||||
+ lines[start])
|
lines[start])
|
||||||
lines[min(end - 1, maxindex)] += '</div>'
|
lines[min(end - 1, maxindex)] += '</div>'
|
||||||
# try to find parents (for submodules)
|
# try to find parents (for submodules)
|
||||||
parents = []
|
parents = []
|
||||||
|
Loading…
Reference in New Issue
Block a user