Skip to content

🐛 5e: emit citation text for non-monster notes - #989

Open
dramamoose wants to merge 1 commit into
ebullient:mainfrom
dramamoose:fix-citations
Open

dramamoose wants to merge 1 commit into
ebullient:mainfrom
dramamoose:fix-citations

Conversation

@dramamoose

Copy link
Copy Markdown

Resolves #988

Problem

{@cite Name|Source|marker} is rendered by handleCitation as a link to a block id ([*](#^citation-…)), and the citation text (which defines that block id) is stashed in ParseState. The stash is only drained by popCitations, which is only called for monster spellcasting (Json2QuteMonster).

For every other note type the citation text is never written. It is discarded when the outermost parse state is popped, which logs:

🛑  ERR| HumblewoodTales p. 149 left unreferenced citations behind

…and the generated note is left with a dead [*](#^citation-…) link.

Example: Hit Point Press' Humblewood Tales marks new items/spells with {@cite New Humblewood Content|HumblewoodTales|*} in its shop inventory tables, feats, subclass spell lists, and adventure chapters.

Fix

Add appendCitations(List<String> text) to JsonTextReplacement. It pops any collected citations and appends them (blank-line separated) to the end of the note body. Call it where note body text is assembled for the types whose data uses {@cite}:

  • book / adventure chapters (Json2QuteBook)
  • tables (Json2QuteTable)
  • feats, spells, items, subclasses

The output format is the existing popCitations format, so these notes match how monster spellcasting citations already render. Monster handling is unchanged.

I didn't use a single generic hook, such as flushing at the end of the outermost appendToText. flattenToString renders table cells through a top-level appendToText, so that approach would put citation text inside table cells.

Verification

I converted 5eTools v2.41.0 plus homebrew (including Humblewood Tales and Flee, Mortals!) with 3.3.9 and with this branch, then diffed the output:

  • "left unreferenced citations behind" errors: 11 → 0
  • notes containing a #^citation-… link with no matching block id: 13 → 0
  • no note defines the same citation block id twice
  • only the 13 affected Humblewood Tales notes changed. Monster notes, including all Flee, Mortals! spellcasting citations, are byte-identical.
  • ./mvnw test with live 5eTools, homebrew and UA data: 214 run, 0 failures (1 skipped).

Example (tables/cathus-inventory-humblewoodtales.md), appended after the table:

^magic-item-price

[citation|new humblewood content|humblewoodtales]: New Humblewood magic items and spells also appear in *italics* and are marked with an asterisk (*) to indicate their details can be found in "Appendix C: Magic Items" and "Appendix D: Spells".
^citation-new-humblewood-content-humblewoodtales

The [key]: text prefix comes from the existing popCitations format, and the raw key shows up as visible text. I left it alone so these notes stay consistent with monsters, but I'm happy to change both if you'd prefer a nicer label.

Not covered: {@cite} in legendary groups, monster fluff, and item properties (one or two uses each in the homebrew repo). Those still log the error.

🤖 Generated with Claude Code

{@cite} renders a link to a block id defined by the citation text, but
the collected citation text was only written for monster spellcasting.
For all other notes it was discarded ("left unreferenced citations
behind"), leaving dead links.

Append collected citations to the body text of book/adventure chapters,
tables, feats, spells, items and subclasses.

Resolves ebullient#988

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: dramamoose <dramamoose@users.noreply.github.com>
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.

🐛 5e: {@cite} outside monster spellcasting leaves dead #^citation-… links ("left unreferenced citations behind")

1 participant