mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Enable automatic formatting for `sphinx/ext/mathjax.py`
This commit is contained in:
@@ -417,7 +417,6 @@ exclude = [
|
|||||||
"sphinx/domains/std/__init__.py",
|
"sphinx/domains/std/__init__.py",
|
||||||
"sphinx/ext/inheritance_diagram.py",
|
"sphinx/ext/inheritance_diagram.py",
|
||||||
"sphinx/ext/linkcode.py",
|
"sphinx/ext/linkcode.py",
|
||||||
"sphinx/ext/mathjax.py",
|
|
||||||
"sphinx/ext/todo.py",
|
"sphinx/ext/todo.py",
|
||||||
"sphinx/ext/viewcode.py",
|
"sphinx/ext/viewcode.py",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -31,10 +31,15 @@ logger = sphinx.util.logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
def html_visit_math(self: HTML5Translator, node: nodes.math) -> None:
|
def html_visit_math(self: HTML5Translator, node: nodes.math) -> None:
|
||||||
self.body.append(self.starttag(node, 'span', '', CLASS='math notranslate nohighlight'))
|
self.body.append(
|
||||||
self.body.append(self.builder.config.mathjax_inline[0] +
|
self.starttag(node, 'span', '', CLASS='math notranslate nohighlight')
|
||||||
self.encode(node.astext()) +
|
)
|
||||||
self.builder.config.mathjax_inline[1] + '</span>')
|
self.body.append(
|
||||||
|
self.builder.config.mathjax_inline[0]
|
||||||
|
+ self.encode(node.astext())
|
||||||
|
+ self.builder.config.mathjax_inline[1]
|
||||||
|
+ '</span>'
|
||||||
|
)
|
||||||
raise nodes.SkipNode
|
raise nodes.SkipNode
|
||||||
|
|
||||||
|
|
||||||
@@ -70,12 +75,16 @@ def html_visit_displaymath(self: HTML5Translator, node: nodes.math_block) -> Non
|
|||||||
raise nodes.SkipNode
|
raise nodes.SkipNode
|
||||||
|
|
||||||
|
|
||||||
def install_mathjax(app: Sphinx, pagename: str, templatename: str, context: dict[str, Any],
|
def install_mathjax(
|
||||||
event_arg: Any) -> None:
|
app: Sphinx,
|
||||||
if (
|
pagename: str,
|
||||||
app.builder.format != 'html' or
|
templatename: str,
|
||||||
app.builder.math_renderer_name != 'mathjax' # type: ignore[attr-defined]
|
context: dict[str, Any],
|
||||||
):
|
event_arg: Any,
|
||||||
|
) -> None:
|
||||||
|
if app.builder.format != 'html':
|
||||||
|
return
|
||||||
|
if app.builder.math_renderer_name != 'mathjax': # type: ignore[attr-defined]
|
||||||
return
|
return
|
||||||
if not app.config.mathjax_path:
|
if not app.config.mathjax_path:
|
||||||
msg = 'mathjax_path config value must be set for the mathjax extension to work'
|
msg = 'mathjax_path config value must be set for the mathjax extension to work'
|
||||||
@@ -89,7 +98,8 @@ def install_mathjax(app: Sphinx, pagename: str, templatename: str, context: dict
|
|||||||
if app.config.mathjax_path == MATHJAX_URL:
|
if app.config.mathjax_path == MATHJAX_URL:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
'mathjax_config/mathjax2_config does not work '
|
'mathjax_config/mathjax2_config does not work '
|
||||||
'for the current MathJax version, use mathjax3_config instead')
|
'for the current MathJax version, use mathjax3_config instead'
|
||||||
|
)
|
||||||
body = 'MathJax.Hub.Config(%s)' % json.dumps(app.config.mathjax2_config)
|
body = 'MathJax.Hub.Config(%s)' % json.dumps(app.config.mathjax2_config)
|
||||||
builder.add_js_file('', type='text/x-mathjax-config', body=body)
|
builder.add_js_file('', type='text/x-mathjax-config', body=body)
|
||||||
if app.config.mathjax3_config:
|
if app.config.mathjax3_config:
|
||||||
@@ -110,9 +120,11 @@ def install_mathjax(app: Sphinx, pagename: str, templatename: str, context: dict
|
|||||||
|
|
||||||
|
|
||||||
def setup(app: Sphinx) -> ExtensionMetadata:
|
def setup(app: Sphinx) -> ExtensionMetadata:
|
||||||
app.add_html_math_renderer('mathjax',
|
app.add_html_math_renderer(
|
||||||
(html_visit_math, None),
|
'mathjax',
|
||||||
(html_visit_displaymath, None))
|
inline_renderers=(html_visit_math, None),
|
||||||
|
block_renderers=(html_visit_displaymath, None),
|
||||||
|
)
|
||||||
|
|
||||||
app.add_config_value('mathjax_path', MATHJAX_URL, 'html')
|
app.add_config_value('mathjax_path', MATHJAX_URL, 'html')
|
||||||
app.add_config_value('mathjax_options', {}, 'html')
|
app.add_config_value('mathjax_options', {}, 'html')
|
||||||
|
|||||||
Reference in New Issue
Block a user