Skip to content

Commit

Permalink
imgmath: Cleanup math dir in embed mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jschueller committed Oct 4, 2022
1 parent 7283402 commit 467c0a2
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions sphinx/ext/imgmath.py
Expand Up @@ -294,6 +294,19 @@ def cleanup_tempdir(app: Sphinx, exc: Exception) -> None:
pass


def cleanup_mathdir(app: Sphinx, exc: Exception) -> None:
if exc:
return
# in embed mode, the images are generated in the math output dir to be
# shared across workers, but are not useful to the document
if app.builder.config.imgmath_embed:
mathdir = path.join(app.builder.outdir, app.builder.imagedir, 'math')
try:
shutil.rmtree(mathdir) # type: ignore
except Exception:
pass


def get_tooltip(self: HTMLTranslator, node: Element) -> str:
if self.builder.config.imgmath_add_tooltips:
return ' alt="%s"' % self.encode(node.astext()).strip()
Expand Down Expand Up @@ -385,4 +398,5 @@ def setup(app: Sphinx) -> Dict[str, Any]:
app.add_config_value('imgmath_font_size', 12, 'html')
app.add_config_value('imgmath_embed', False, 'html', [bool])
app.connect('build-finished', cleanup_tempdir)
app.connect('build-finished', cleanup_mathdir)
return {'version': sphinx.__display_version__, 'parallel_read_safe': True}

0 comments on commit 467c0a2

Please sign in to comment.