mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
refactor: Access config object from self directly in writers
This commit is contained in:
parent
d9569a84a2
commit
410b8e03f3
@ -315,7 +315,7 @@ class HTMLTranslator(SphinxTranslator, BaseTranslator):
|
||||
|
||||
if figure_id in self.builder.fignumbers.get(key, {}):
|
||||
self.body.append('<span class="caption-number">')
|
||||
prefix = self.builder.config.numfig_format.get(figtype)
|
||||
prefix = self.config.numfig_format.get(figtype)
|
||||
if prefix is None:
|
||||
msg = __('numfig_format is not defined for %s') % figtype
|
||||
logger.warning(msg)
|
||||
@ -439,14 +439,14 @@ class HTMLTranslator(SphinxTranslator, BaseTranslator):
|
||||
linenos = node.get('linenos', False)
|
||||
highlight_args = node.get('highlight_args', {})
|
||||
highlight_args['force'] = node.get('force', False)
|
||||
if lang is self.builder.config.highlight_language:
|
||||
if lang is self.config.highlight_language:
|
||||
# only pass highlighter options for original language
|
||||
opts = self.builder.config.highlight_options
|
||||
opts = self.config.highlight_options
|
||||
else:
|
||||
opts = {}
|
||||
|
||||
if linenos and self.builder.config.html_codeblock_linenos_style:
|
||||
linenos = self.builder.config.html_codeblock_linenos_style
|
||||
if linenos and self.config.html_codeblock_linenos_style:
|
||||
linenos = self.config.html_codeblock_linenos_style
|
||||
|
||||
highlighted = self.highlighter.highlight_block(
|
||||
node.rawsource, lang, opts=opts, linenos=linenos,
|
||||
|
@ -286,7 +286,7 @@ class HTML5Translator(SphinxTranslator, BaseTranslator):
|
||||
|
||||
if figure_id in self.builder.fignumbers.get(key, {}):
|
||||
self.body.append('<span class="caption-number">')
|
||||
prefix = self.builder.config.numfig_format.get(figtype)
|
||||
prefix = self.config.numfig_format.get(figtype)
|
||||
if prefix is None:
|
||||
msg = __('numfig_format is not defined for %s') % figtype
|
||||
logger.warning(msg)
|
||||
@ -390,14 +390,14 @@ class HTML5Translator(SphinxTranslator, BaseTranslator):
|
||||
linenos = node.get('linenos', False)
|
||||
highlight_args = node.get('highlight_args', {})
|
||||
highlight_args['force'] = node.get('force', False)
|
||||
if lang is self.builder.config.highlight_language:
|
||||
if lang is self.config.highlight_language:
|
||||
# only pass highlighter options for original language
|
||||
opts = self.builder.config.highlight_options
|
||||
opts = self.config.highlight_options
|
||||
else:
|
||||
opts = {}
|
||||
|
||||
if linenos and self.builder.config.html_codeblock_linenos_style:
|
||||
linenos = self.builder.config.html_codeblock_linenos_style
|
||||
if linenos and self.config.html_codeblock_linenos_style:
|
||||
linenos = self.config.html_codeblock_linenos_style
|
||||
|
||||
highlighted = self.highlighter.highlight_block(
|
||||
node.rawsource, lang, opts=opts, linenos=linenos,
|
||||
|
@ -523,7 +523,7 @@ class LaTeXTranslator(SphinxTranslator):
|
||||
|
||||
ret = []
|
||||
# latex_domain_indices can be False/True or a list of index names
|
||||
indices_config = self.builder.config.latex_domain_indices
|
||||
indices_config = self.config.latex_domain_indices
|
||||
if indices_config:
|
||||
for domain in self.builder.env.domains.values():
|
||||
for indexcls in domain.indices:
|
||||
@ -543,7 +543,7 @@ class LaTeXTranslator(SphinxTranslator):
|
||||
|
||||
def render(self, template_name: str, variables: Dict) -> str:
|
||||
renderer = LaTeXRenderer(latex_engine=self.config.latex_engine)
|
||||
for template_dir in self.builder.config.templates_path:
|
||||
for template_dir in self.config.templates_path:
|
||||
template = path.join(self.builder.confdir, template_dir,
|
||||
template_name)
|
||||
if path.exists(template):
|
||||
@ -963,7 +963,7 @@ class LaTeXTranslator(SphinxTranslator):
|
||||
cell = self.table.cell()
|
||||
context = ''
|
||||
if cell.width > 1:
|
||||
if self.builder.config.latex_use_latex_multicolumn:
|
||||
if self.config.latex_use_latex_multicolumn:
|
||||
if self.table.col == 0:
|
||||
self.body.append('\\multicolumn{%d}{|l|}{%%\n' % cell.width)
|
||||
else:
|
||||
@ -1543,7 +1543,7 @@ class LaTeXTranslator(SphinxTranslator):
|
||||
id = self.curfilestack[-1] + ':' + uri[1:]
|
||||
self.body.append(self.hyperlink(id))
|
||||
self.body.append(r'\emph{')
|
||||
if self.builder.config.latex_show_pagerefs and not \
|
||||
if self.config.latex_show_pagerefs and not \
|
||||
self.in_production_list:
|
||||
self.context.append('}}} (%s)' % self.hyperpageref(id))
|
||||
else:
|
||||
@ -1567,8 +1567,7 @@ class LaTeXTranslator(SphinxTranslator):
|
||||
self.body.append(r'\sphinxtermref{')
|
||||
else:
|
||||
self.body.append(r'\sphinxcrossref{')
|
||||
if self.builder.config.latex_show_pagerefs and not \
|
||||
self.in_production_list:
|
||||
if self.config.latex_show_pagerefs and not self.in_production_list:
|
||||
self.context.append('}}} (%s)' % self.hyperpageref(id))
|
||||
else:
|
||||
self.context.append('}}}')
|
||||
@ -1752,9 +1751,9 @@ class LaTeXTranslator(SphinxTranslator):
|
||||
linenos = node.get('linenos', False)
|
||||
highlight_args = node.get('highlight_args', {})
|
||||
highlight_args['force'] = node.get('force', False)
|
||||
if lang is self.builder.config.highlight_language:
|
||||
if lang is self.config.highlight_language:
|
||||
# only pass highlighter options for original language
|
||||
opts = self.builder.config.highlight_options
|
||||
opts = self.config.highlight_options
|
||||
else:
|
||||
opts = {}
|
||||
|
||||
@ -2018,12 +2017,12 @@ class LaTeXTranslator(SphinxTranslator):
|
||||
else:
|
||||
from sphinx.util.math import wrap_displaymath
|
||||
self.body.append(wrap_displaymath(node.astext(), label,
|
||||
self.builder.config.math_number_all))
|
||||
self.config.math_number_all))
|
||||
raise nodes.SkipNode
|
||||
|
||||
def visit_math_reference(self, node: Element) -> None:
|
||||
label = "equation:%s:%s" % (node['docname'], node['target'])
|
||||
eqref_format = self.builder.config.math_eqref_format
|
||||
eqref_format = self.config.math_eqref_format
|
||||
if eqref_format:
|
||||
try:
|
||||
ref = r'\ref{%s}' % label
|
||||
@ -2088,7 +2087,7 @@ class LaTeXTranslator(SphinxTranslator):
|
||||
warnings.warn('generate_numfig_format() is deprecated.',
|
||||
RemovedInSphinx40Warning, stacklevel=2)
|
||||
ret = [] # type: List[str]
|
||||
figure = self.builder.config.numfig_format['figure'].split('%s', 1)
|
||||
figure = self.config.numfig_format['figure'].split('%s', 1)
|
||||
if len(figure) == 1:
|
||||
ret.append('\\def\\fnum@figure{%s}\n' % self.escape(figure[0]).strip())
|
||||
else:
|
||||
@ -2099,7 +2098,7 @@ class LaTeXTranslator(SphinxTranslator):
|
||||
self.escape(figure[1]))
|
||||
ret.append('\\makeatother\n')
|
||||
|
||||
table = self.builder.config.numfig_format['table'].split('%s', 1)
|
||||
table = self.config.numfig_format['table'].split('%s', 1)
|
||||
if len(table) == 1:
|
||||
ret.append('\\def\\fnum@table{%s}\n' % self.escape(table[0]).strip())
|
||||
else:
|
||||
@ -2110,7 +2109,7 @@ class LaTeXTranslator(SphinxTranslator):
|
||||
self.escape(table[1]))
|
||||
ret.append('\\makeatother\n')
|
||||
|
||||
codeblock = self.builder.config.numfig_format['code-block'].split('%s', 1)
|
||||
codeblock = self.config.numfig_format['code-block'].split('%s', 1)
|
||||
if len(codeblock) == 1:
|
||||
pass # FIXME
|
||||
else:
|
||||
|
@ -296,8 +296,7 @@ class ManualPageTranslator(SphinxTranslator, BaseTranslator):
|
||||
if uri.startswith('mailto:') or uri.startswith('http:') or \
|
||||
uri.startswith('https:') or uri.startswith('ftp:'):
|
||||
# if configured, put the URL after the link
|
||||
if self.builder.config.man_show_urls and \
|
||||
node.astext() != uri:
|
||||
if self.config.man_show_urls and node.astext() != uri:
|
||||
if uri.startswith('mailto:'):
|
||||
uri = uri[7:]
|
||||
self.body.extend([
|
||||
|
@ -233,12 +233,12 @@ class TexinfoTranslator(SphinxTranslator):
|
||||
'author': self.settings.author,
|
||||
# if empty, use basename of input file
|
||||
'filename': self.settings.texinfo_filename,
|
||||
'release': self.escape(self.builder.config.release),
|
||||
'project': self.escape(self.builder.config.project),
|
||||
'copyright': self.escape(self.builder.config.copyright),
|
||||
'date': self.escape(self.builder.config.today or
|
||||
format_date(self.builder.config.today_fmt or _('%b %d, %Y'),
|
||||
language=self.builder.config.language))
|
||||
'release': self.escape(self.config.release),
|
||||
'project': self.escape(self.config.project),
|
||||
'copyright': self.escape(self.config.copyright),
|
||||
'date': self.escape(self.config.today or
|
||||
format_date(self.config.today_fmt or _('%b %d, %Y'),
|
||||
language=self.config.language))
|
||||
})
|
||||
# title
|
||||
title = self.settings.title # type: str
|
||||
@ -434,7 +434,7 @@ class TexinfoTranslator(SphinxTranslator):
|
||||
self.add_menu_entries(entries)
|
||||
if (node_name != 'Top' or
|
||||
not self.node_menus[entries[0]] or
|
||||
self.builder.config.texinfo_no_detailmenu):
|
||||
self.config.texinfo_no_detailmenu):
|
||||
self.body.append('\n@end menu\n')
|
||||
return
|
||||
|
||||
@ -484,7 +484,7 @@ class TexinfoTranslator(SphinxTranslator):
|
||||
ret.append('@end menu\n')
|
||||
return ''.join(ret)
|
||||
|
||||
indices_config = self.builder.config.texinfo_domain_indices
|
||||
indices_config = self.config.texinfo_domain_indices
|
||||
if indices_config:
|
||||
for domain in self.builder.env.domains.values():
|
||||
for indexcls in domain.indices:
|
||||
@ -739,7 +739,7 @@ class TexinfoTranslator(SphinxTranslator):
|
||||
else:
|
||||
uri = self.escape_arg(uri)
|
||||
name = self.escape_arg(name)
|
||||
show_urls = self.builder.config.texinfo_show_urls
|
||||
show_urls = self.config.texinfo_show_urls
|
||||
if self.in_footnote:
|
||||
show_urls = 'inline'
|
||||
if not name or uri == name:
|
||||
@ -1395,9 +1395,8 @@ class TexinfoTranslator(SphinxTranslator):
|
||||
# use the full name of the objtype for the category
|
||||
try:
|
||||
domain = self.builder.env.get_domain(node.parent['domain'])
|
||||
primary = self.builder.config.primary_domain
|
||||
name = domain.get_type_name(domain.object_types[objtype],
|
||||
primary == domain.name)
|
||||
self.config.primary_domain == domain.name)
|
||||
except (KeyError, ExtensionError):
|
||||
name = objtype
|
||||
# by convention, the deffn category should be capitalized like a title
|
||||
|
Loading…
Reference in New Issue
Block a user