Skip to content

Commit

Permalink
Reset Sphinx env in lineref code blocks to update references
Browse files Browse the repository at this point in the history
Running new builds without deleting the `_build` directory first
used to cause warnings "Line reference labels should be unique".
This commit deletes the build environment variable at the start of
the build so that the new build updates the line references
correctly and does not emit warnings.
  • Loading branch information
markkuriekkinen committed Dec 2, 2022
1 parent 20c331a commit ff7bd5e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions directives/codeblock_lineref.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,18 @@ def lineref_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
return [linknode], []


def _reset_env_code_line_labels(app):
env = app.builder.env
if hasattr(env, 'code_line_labels'):
del env.code_line_labels


def setup(app):
app.add_directive('lineref-code-block', LineRefCodeBlock)
app.add_node(codeblock_lineref,
html=(visit_codeblock_lineref_node, depart_codeblock_lineref_node),
latex=(visit_codeblock_lineref_node, depart_codeblock_lineref_node),
text=(visit_codeblock_lineref_node, depart_codeblock_lineref_node))
app.add_role('lref', lineref_role)

app.connect("builder-inited", _reset_env_code_line_labels)

0 comments on commit ff7bd5e

Please sign in to comment.