fix: escape makeindex control characters in plain index entries - #54
Open
eastagiletracker wants to merge 1 commit into
Open
Conversation
rewriteIndexEntry() returned the entry untouched whenever it held
neither a code span nor a non-ASCII character, which skipped
quoteForMakeindex() for that whole class of terms. A literal `!` then
reached \index{...} unquoted, where makeindex reads it as the
sub-entry separator: `Snap! program` was filed under "Snap" with a
"program" sub-entry, and `SciSnap!`, `starting Snap!` and `source
files for Snap!` each got an empty sub-entry. The same character was
escaped correctly in entries that happened to contain backticks,
since only those took the rewrite path.
Quote on the early-return path too, so the escaping the function's
own comment describes applies to every entry. This also makes the
`!` block's `block; !` entry compile as a literal sub-entry instead
of \index{block!!}.
Sub-entry separators are unaffected: myst-to-tex joins entry and
subEntry with `!` after this transform runs, so `Snap; logo menu`
still emits \index{Snap!logo menu}.
Adds unit tests for the transform, run with `npm test` via Node's
built-in test runner (no new dependencies).
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 PR proposes escaping makeindex control characters in plain index entries, so terms like
Snap! programandSciSnap!stop being split into a main entry and a stray sub-entry in the printed index. We include this PR work along with a full history of your repo at https://eastagiletracker.com/projects/209. You can sign in with your GitHub ID to claim ownership of the project.What's wrong
rewriteIndexEntry()in_support/plugins/latex-shims.mjsreturns an index entry untouched whenever it contains neither a code span nor a non-ASCII character:That early return skips
quoteForMakeindex(), so for that whole class of terms a literal!reaches\index{...}unquoted — and makeindex reads it as the sub-entry separator, exactly asdocs/STYLEGUIDE.mdand the comment abovequoteForMakeindex()both describe. The escaping ends up coupled to an unrelated condition: the same character is quoted in an entry that happens to contain backticks and left bare in the one next to it.Reproduced on
mainat eecf1d9:So in the shipped index,
Snap! programfiles under Snap with a "program" sub-entry, andSciSnap!,starting Snap!andsource files for Snap!each hang an empty sub-entry off a truncated term. In a manual whose index is a published artifact, the language's own name is the term most likely to be looked up.This is also what the note at
01-blocks-scripts-and-sprites.md:1928is about —<!-- I cannot figure out an index format that compiles this... -->. The directive under it is:::{index} `!` block, block; !: the first half has backticks so it takes the rewrite path and compiles fine, whileblock; !produces\index{block!!}. I left that comment in place rather than assume it should go; happy to drop it here or in a follow-up.The change
Quote on the early-return path too, so the escaping the function's own comment describes applies to every entry:
Sub-entry separators are untouched, because myst-to-tex joins
entryandsubEntrywith!after this transform runs —:::{index} Snap; logo menustill emits\index{Snap!logo menu}, and the diff below confirms it.Verification
Same build, after the change — the generated LaTeX differs in exactly six entries out of 880, and in nothing else:
npx myst build --texandmyst build --htmlwere run before and after: the error set is byte-identical (28 lines both times — the pre-existing imagemagick/SVG andmystRoleErrornotices), and no new failures appear. The HTML build is unaffected by construction, since the transform returns early on non-LaTeX builds.The PR also adds
_support/plugins/latex-shims.test.mjswith 8 unit tests for the transform, wired tonpm testthrough Node's built-in test runner — no new dependencies. Two of them fail onmainand pass here; I confirmed that by reverting only the behavioral line and re-running:They also cover the cases that must not change —
palette,hat block,Ball, Michael— plus@,|and", trailing backslashes, code spans, the⚡/➔sort keys, and non-string input.How this was managed
This work was tracked as a story on the board, on a project imported from this repository's own issues and pull requests — 53 stories in all — and used to manage the change end to end.
If you'd rather not receive contributions like this, reply
no-more-prson this pull request and we won't open any further ones on your repositories.Lawrence W. Sinclair
CEO / East Agile
linkedin.com/in/lwsinclair/
eastagile.com