Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
first draft to expand a number for issue #43
Browse files Browse the repository at this point in the history
  • Loading branch information
sdpython committed Dec 31, 2016
1 parent ab9a13c commit d4db650
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/pyquickhelper/sphinxext/sphinx_mathdef_extension.py
Expand Up @@ -87,6 +87,14 @@ def run(self):
else:
legend = ''

if hasattr(env, "settings") and hasattr(env.settings, "mathdef_link_number"):
number_format = env.settings.mathdef_link_number
elif hasattr(self.state.document.settings, "mathdef_link_number"):
number_format = self.state.document.settings.mathdef_link_number
else:
raise ValueError(
"mathdef_link_number is not defined in the configuration")

if not self.options.get('class'):
self.options['class'] = ['admonition-mathdef']

Expand Down Expand Up @@ -114,10 +122,16 @@ def run(self):
else:
mid = -1

# id of the section
first_letter = docname[0] if docname else ""
number = mid
label_number = number_format.format(
number=number, first_letter=first_letter)

# title
title = self.options.get('title', "").strip()
if len(title) > 0:
title = "{0} {1} : {2}".format(mathtag, mid, title)
title = "{0} {1} : {2}".format(mathtag, label_number, title)
else:
raise ValueError("title is empty")

Expand Down Expand Up @@ -425,6 +439,8 @@ def setup(app):

app.add_config_value('mathdef_include_mathsext', True, 'html')
app.add_config_value('mathdef_link_only', True, 'html')
app.add_config_value('mathdef_link_number',
"{first_letter}.{number}", 'html')

app.add_node(mathdeflist,
html=(visit_mathdeflist_node, depart_mathdeflist_node),
Expand Down

0 comments on commit d4db650

Please sign in to comment.