Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit 8be9e13

Browse files
committed
Fix: Correct bug producing null subchapters.
1 parent e60c737 commit 8be9e13

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

runestone/chapterdb/dbchapterinfo.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
# You should have received a copy of the GNU General Public License
1414
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1515
#
16+
# **************************************************************
17+
# |docname| - Record chapter info in the database during a build
18+
# **************************************************************
1619

1720
__author__ = "bmiller"
1821

19-
import os.path
22+
from typing import Sequence
2023
from collections import OrderedDict
2124
import docutils
22-
import pdb
2325
from sphinx.util import logging
2426

2527
logger = logging.getLogger(__name__)
@@ -43,7 +45,6 @@ def env_updated(app, doctree, docname):
4345
"""
4446
This may be the best place to walk the completed document with TOC
4547
"""
46-
# pdb.set_trace()
4748
# ``docname`` is stored with Unix-style forward slashes, even on Windows. Therefore, we can't use ``os.path.basename`` or ``os.sep``.
4849
splits = docname.split("/")
4950
# If the docname is ``'index'``, then set ``chap_id`` to an empty string.
@@ -76,7 +77,6 @@ def env_updated(app, doctree, docname):
7677
secnum_str = ".".join(map(str, secnum_tuple)) + " " if secnum_tuple else ""
7778
# Prepend it to the title.
7879
title = secnum_str + section.next_node(docutils.nodes.Titular).astext()
79-
# pdb.set_trace()
8080

8181
if hasattr(app.env, "skipreading") and docname in app.env.skipreading:
8282
app.env.skips[(chap_id, subchap_id)] = True
@@ -106,11 +106,18 @@ def env_updated(app, doctree, docname):
106106
return []
107107

108108

109-
def make_subchap_num(sn_tuple):
110-
if not sn_tuple:
109+
# Given a sequence of section numbers, produce a single (orderable) int from the subchapter number and optionally the subsubchapter. Any finer divisions are ignored.
110+
def make_subchap_num(
111+
# A sequence of section numbers in the format ``(chapter, subchapter, optional_subsubchapter, ignored_stuff...)``.
112+
sn_seq: Sequence[int]
113+
# Returns subchapter*100 + optional_subsubchapter.
114+
) -> int:
115+
if not sn_seq or len(sn_seq) < 2:
111116
return 0
112117

113-
if len(sn_tuple) > 2:
114-
return sn_tuple[1] * 100 + sn_tuple[2]
115-
elif len(sn_tuple) == 2:
116-
return sn_tuple[1] * 100
118+
# Ignore the chapter number at ``sn_tuple[0]`` -- we're creating a subchapter number.
119+
ret = sn_seq[1] * 100
120+
# Include the subsubchapter number if it exists. Ignore everything else.
121+
if len(sn_seq) > 2:
122+
ret += sn_seq[2]
123+
return ret

0 commit comments

Comments
 (0)