Skip to content

Use PTX genreated chapter numbers when processing manifest#1313

Merged
bnmnetp merged 1 commit into
RunestoneInteractive:mainfrom
ascholerChemeketa:issue-1310-fix
Jul 21, 2026
Merged

Use PTX genreated chapter numbers when processing manifest#1313
bnmnetp merged 1 commit into
RunestoneInteractive:mainfrom
ascholerChemeketa:issue-1310-fix

Conversation

@ascholerChemeketa

Copy link
Copy Markdown
Contributor

Fix for #1310

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses Runestone issue #1310 where assignment reading chapter numbers are off by one, by switching chapter/subchapter numbering to use the PreTeXt (PTX) manifest-provided <number> values rather than purely sequential counters.

Changes:

  • Use manifest <number> for chapters.chapter_num when processing chapters.
  • Parse manifest subchapter numbers like "1.1" to store/display only the subchapter portion (e.g., "1").
  • Rename internal counters for clarity (chapter_counter, subchap_counter).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread components/rsptx/build_tools/core.py Outdated
Comment on lines +690 to +692
cnum = chapter.find("./number").text
if not cnum:
cnum = ""
cnum = chap_counter
Comment on lines +756 to +757
else:
scnum = subchap_counter
sub_chapter_label=subchapter.find("./id").text,
skipreading="F",
sub_chapter_num=subchap_num,
sub_chapter_num=scnum,
Copilot AI review requested due to automatic review settings July 21, 2026 17:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (2)

components/rsptx/build_tools/core.py:694

  • chapter.find("./number").text can raise AttributeError when the <number> element is missing, and int(cnum_text) can raise ValueError if the manifest contains whitespace or a non-integer value. Since the code already has a fallback to the counter, it should safely read and parse the text (including stripping) and fall back on parse errors.
    cnum_text = chapter.find("./number").text
    if not cnum_text:
        cnum = chap_counter
    else:
        cnum = int(cnum_text)

components/rsptx/build_tools/core.py:756

  • subchapter.find("./number").text can raise AttributeError if the <number> element is missing, and the int() conversion will raise if the value includes unexpected whitespace or a non-integer (e.g., malformed x.y). Use findtext() + strip() and fall back to subchap_counter on parse errors to avoid failing the whole manifest load.
    scnum_text = subchapter.find("./number").text
    if scnum_text:
        # subchapter numbers are in manifest as "1.1", "1.2", etc.
        # strip off the chapter number and just keep the subchapter number
        if "." in scnum_text:

@ascholerChemeketa

Copy link
Copy Markdown
Contributor Author

Pushed with updates for Copilot review

@bnmnetp
bnmnetp merged commit 431ae72 into RunestoneInteractive:main Jul 21, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants