-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MonkeyPatch how Sphinx handle numbered references
Sphinx treats references globally, so if the toctree is not numbered the counting increments across the pages. This patch changes this behaviour to always reset the count per page. Bump version. Signed-off-by: Jorge Marques <[email protected]>
- Loading branch information
Showing
9 changed files
with
120 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from sphinx.environment.collectors.toctree import TocTreeCollector | ||
|
||
def monkeypatch_figure_numbers(): | ||
""" | ||
Reset reference counting per page, even when the toctree is not numbered. | ||
If the toctree is numbered, the offset should resolve as 0. | ||
""" | ||
old_assign_figure_numbers = TocTreeCollector.assign_figure_numbers | ||
|
||
def assign_figure_numbers(self, env): | ||
rewrite_needed = old_assign_figure_numbers(self, env) | ||
for entry in env.toc_fignumbers: | ||
for type_ in env.toc_fignumbers[entry]: | ||
if len(env.toc_fignumbers[entry][type_]) > 0: | ||
offset = env.toc_fignumbers[entry][type_][next(iter(env.toc_fignumbers[entry][type_]))][-1] - 1 | ||
for id_ in env.toc_fignumbers[entry][type_]: | ||
tuple_ = list(env.toc_fignumbers[entry][type_][id_]) | ||
tuple_[-1] = tuple_[-1]-offset | ||
env.toc_fignumbers[entry][type_][id_] = tuple(tuple_) | ||
return rewrite_needed | ||
|
||
TocTreeCollector.assign_figure_numbers = assign_figure_numbers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,6 @@ | |
@import "related"; | ||
@import "code"; | ||
@import "print"; | ||
@import "caption"; | ||
@import "directive"; | ||
@import "table"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.caption-number { | ||
color: var(--text-color2); | ||
} | ||
|
||
.caption-number:after { | ||
content: ':'; | ||
margin-left: -.3em; | ||
margin-right: .2em; | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
a { | ||
display: flex; | ||
align-items: center; | ||
max-width: 50%; | ||
} | ||
|
||
.prev { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
.table-wrapper { | ||
margin-bottom: .5em; | ||
} | ||
|
||
table.docutils { | ||
border-spacing: 0; | ||
border-radius: $border-radius; | ||
border: $border-td; | ||
|
||
thead { | ||
background-color: var(--bg-color2); | ||
} | ||
|
||
th { | ||
border-bottom: $border-th; | ||
} | ||
|
||
td { | ||
border-bottom: $border-td; | ||
} | ||
|
||
p { | ||
margin: 0; | ||
text-align: left; | ||
} | ||
|
||
th, td { | ||
padding: .5em; | ||
} | ||
|
||
tr:last-child td { | ||
border-bottom: none; | ||
} | ||
|
||
thead:not(:first-child) th { | ||
font-weight: normal; | ||
} | ||
|
||
&.grid { | ||
td:not(:first-child), th:not(:first-child) { | ||
border-left: $border-td; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters