Repository navigation
Build divisions of a document as SCORM packages of their own (experimental) - #1269
Merged
Merged
Conversation
Plan for building each chosen division of one document as its own SCORM package or PDF from a single target, with a runnable spike project that proves the approach: a CLI-supplied stylesheet prunes the assembled tree to one division, keeping the numbers it has in the full document. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A pdf or latex target with division="<xml:id>" builds only that division. A stylesheet shipped with the CLI prunes core's assembled, numbered tree down to the division and shells of its ancestors, so the division keeps the numbers it has in the whole document. LaTeX's own counters are set from those numbers, a cross-reference leaving the division shows its text without a link, and an article prints no title block above the division's heading. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The division attribute now also applies to html targets. The division is one page, with no table of contents, search, or buttons to pages that do not exist. With compression the CLI zips the build itself, so a SCORM package gets a manifest identifier of its own and leaves out source maps and compressed duplicates, about a fifth of the usual size. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A target with collection="..." builds several divisions of its source, each as the division attribute would build it and named for its xml:id. The collection lists kinds of division (every worksheet with an xml:id) and single divisions (an xml:id after a #). With an output-filename the results are also gathered into one zip file of that name. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Building divisions as HTML pages and SCORM packages is now the supported use. The PDF and LaTeX route stays as a draft on hold: such a target warns when built, and the changelog, schema and stylesheet say so. For HTML and SCORM: a cross-reference with a list or range of targets outside the division shows its usual text in place of core's placeholder; a division with no title takes its default title, so a package is never nameless; the division's heading is an h2 under the banner, not an h6; and a document with no document-id or root xml:id is named in the manifest identifier by a slug of its title. For collections: output-filename must end in .zip, uncompressed HTML can be gathered into a zip too, an earlier zip is removed before building, -x is reported as ignored, and a missing # or a comma gets a pointed error. The roadmap records the change of course: numbering is reopened, and collections of slideshows are a later goal. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A target now names the divisions to build with divisions="...", a list of words separated by spaces. A word that is a kind of division selects every division of that kind that has an xml:id; any other word is the xml:id of one division. A # before a word still forces it to be read as an xml:id. Such a target always makes a set: one output per division, named for its xml:id, even when one division is selected. An output-filename always names a zip of all the outputs. Uncompressed HTML also gets an index.html listing the divisions, for pretext view to open. Assets are generated once for the whole document, so the record of them is saved. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Standalone targets build a one-off document without a project, and stay. A quick way to build one division of a project, made with divisions underneath, is recorded as a project for another time. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A division built by an html target with divisions is now numbered as if it were the root of the document: it has no number of its own, and the divisions, blocks and equations inside it count from 1, so a worksheet's first table is "Table 1" and not "Table 5.3.1". The new attribute division-numbering="document" keeps the whole document's numbers, which is still what pdf and latex targets do. Core's last two assembly passes go only by where an element sits in the tree, so a further stylesheet runs them again on the pruned tree. One named template of core's, which pads a block's number to the numbering level, is replaced there to leave out the division's own depth. A cross-reference that leaves the division shows the target's number in the whole document. Also read built pages as UTF-8 in the tests, which failed on Windows. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds an experimental
divisionsattribute to a target. It builds chosen divisions of the source, each as a document of its own, from one build. The use it is meant for now is one SCORM package per weekly worksheet, made from a single course document, so each can be uploaded to an LMS as its own assignment.What it does
divisionsis a list of words separated by spaces. A word that is a kind of division (chapter,section,subsection,subsubsection,worksheet,handout,exercises,reading-questions) selects every division of that kind that has anxml:id. Any other word is thexml:idof one division.xml:id, even when one division is selected:hw-01.zipwithcompression, or a directoryhw-01/without. Anoutput-filename, which must end in.zip, names one zip of them all.division-numbering="document"keeps the whole document's numbers instead.ptx-<document>-<division>) and leaves out source maps and compressed duplicates, which brings a package from about 10 MB to about 2 MB.index.htmllisting the divisions, sopretext viewhas a page to open.How it works
Nothing in core changes, and
CORE_COMMITis not moved. Stylesheets shipped inpretext/resources/division/import core's converter and override$root,$docinfoand$document-rootwith a pruned copy of core's final assembled tree: the division, whole, plus empty shells of its ancestors. Core's own comment above those variables says a conversion may override them. The cut is made after core has stamped its numbers, so withdivision-numbering="document"the division keeps them.Numbering afresh, the default for HTML, re-runs core's last two assembly passes (
augmentandserial-stamp) on the pruned tree; both go only by where an element sits in the tree they are given. One named template of core's,block-structure-number, is replaced so that a block's number leaves out the division's own depth. That is the one place core's logic is copied, about twenty lines, and it has to be kept in step withpretext-numbers.xsl.This does lean on core internals by name (
$serial-stamp, thepi:number stamps, a few modal templates), so the tests here are the guard whenCORE_COMMITmoves.A target with
divisionscopies itself once per selected division and builds each copy. Assets are generated once, for the whole document.PDF and LaTeX: a draft, on hold
divisionsis also accepted onpdfandlatextargets. That route is not ready and Oscar has paused it. It is known to be wrong for a division inside an appendix or a part, footnote numbers restart, and only the last division's LaTeX source is kept. Such a target logs a warning when built, and the CHANGELOG, the manifest schema and the stylesheet all say it is a draft. The alternative is to remove that code from this pull request; it is left in so the work is not lost.Testing
tests/test_project.pyhas 29 tests for this, on a new example projecttests/examples/projects/division(a small book and the same document as an article).tests/test_utils.pycovers the zip and naming helpers.tests/test_project.pyandtests/test_utils.pypass in full locally (106 passed, 1 skipped), and flake8 is clean. mypy reports only missingpsutilstubs in the local environment.f6d4b762d, not the pinned commit. CI runs against the pin, and every job passes on the current head (8c3e8cf), on Linux and Windows. An earlier push failed on Windows in two tests that read a built page without naming UTF-8; that is fixed.Known gaps
These are recorded, with more detail, in
docs/subset-build-roadmap.md:external/andgenerated/, including files used only by other divisions. That is wasted size, and for quizzes it discloses other quizzes' files.-xis ignored by a target withdivisions, with a warning.For the reviewer
docs/subset-build-roadmap.mdis the design record, including decisions made and reversed.docs/subset-spike/is the runnable spike that preceded the implementation; it duplicates the shipped stylesheets in an earlier form and could be dropped before merging.divisionandcollection, merged intodivisions, and first kept the whole document's numbers. Reading the final state is easier than reading commit by commit.divisions, since unknown target attributes are refused.Claude Fable 5.2, acting as a coding assistant for Oscar Levin