Skip to content

fix(core/render-biblio): sanitize spaces in reference IDs#5177

Merged
marcoscaceres merged 8 commits intomainfrom
fix/biblio-id-spaces
Apr 16, 2026
Merged

fix(core/render-biblio): sanitize spaces in reference IDs#5177
marcoscaceres merged 8 commits intomainfrom
fix/biblio-id-spaces

Conversation

@marcoscaceres
Copy link
Copy Markdown
Contributor

Reference names with spaces (e.g. 'Ruby TTS Req') produced invalid HTML IDs containing spaces. Consolidates all bib- ID generation through a bibRefId() helper that replaces whitespace with hyphens.

Closes #5102

Reference names with spaces (e.g. 'Ruby TTS Req') produced invalid HTML
IDs containing spaces. Consolidates all bib- ID generation through a
bibRefId() helper that replaces whitespace with hyphens.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes invalid HTML id generation for bibliography entries when reference keys contain whitespace by centralizing bib fragment/id creation in a helper that replaces whitespace with hyphens.

Changes:

  • Add bibRefId(ref) helper to generate bib-... IDs with whitespace normalized to -.
  • Update inline citation rendering to link to #${bibRefId(key)}.
  • Update reference list rendering and alias/warn selectors to use the same normalized bib IDs.

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

Comment thread src/core/render-biblio.js Outdated
@marcoscaceres
Copy link
Copy Markdown
Contributor Author

marcoscaceres commented Apr 13, 2026

Hmmm... definitely need a test for this one.

The examples are wild:

	  'Tokyo Ghoul: re': {
              title: "Tokyo Ghoul: re, Vol. 8, Chapter 76 “Daso (惰疎)",
              authors: ["Sui Ishida"], 
              id: "Tokyo Groul: re 8-76",
              date: "2016",
              publisher: "Shueisha",
          },
          'Transliteration Training Course': {
              title: "Textbook for the Volunteer Transliteration Training Course: Basics (In Japanese, 音訳ボランティア養成講習会テキスト 基礎課程編)",
	      href: "https://naiiv-books.net/shopdetail/000000000023/",
            date: "March 2010",
            publisher: "National Council of Japan for the Visually Impaired (In Japanese, 全国視覚障害者情報提供施設協会)",
          },

As I never expected ids from bib-ref to be used this way (they follow the short name rules from w3c)... but sure, why not!

@marcoscaceres
Copy link
Copy Markdown
Contributor Author

@copilot can you add tests. See my comment above?

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 13, 2026

Hmmm... definitely need a test for this one.

The examples are wild:
...

Tests added in a077412. The new "generates valid HTML IDs for reference keys that contain spaces" test uses your exact "Ruby TTS Req" and "Tokyo Ghoul: re" examples from the comment. It asserts:

  • dt IDs have spaces replaced by hyphens (bib-ruby-tts-req, bib-tokyo-ghoul:-re)
  • Inline citation href fragments match those sanitized IDs

@copilot can you add tests. See my comment above?

Done in commit a077412 — added a regression test using the "Ruby TTS Req" and "Tokyo Ghoul: re" examples.

Comment thread src/core/render-biblio.js Outdated
…sanitization

Agent-Logs-Url: https://github.com/speced/respec/sessions/8d7688e3-f620-40d2-87bd-e2851412f88b

Co-authored-by: marcoscaceres <870154+marcoscaceres@users.noreply.github.com>
Comment thread src/core/utils.js
Agent-Logs-Url: https://github.com/speced/respec/sessions/2ea95651-690e-47f4-9566-f25caed403e1

Co-authored-by: marcoscaceres <870154+marcoscaceres@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 13, 2026

Hmmm... definitely need a test for this one.

The examples are wild:
...

Tests were added (a077412) and the sanitization was subsequently broadened (bc35789) to use the existing addId normalization pipeline — so colons, parens, diacritics, etc. are all handled correctly. "Tokyo Ghoul: re"bib-tokyo-ghoul-re, "Ruby TTS Req"bib-ruby-tts-req.

@copilot can you add tests. See my comment above?

Done in a077412 (regression tests for spaces) and updated in bc35789 (broader sanitization via toId). Full toId unit tests added in acc0613.

@marcoscaceres
Copy link
Copy Markdown
Contributor Author

@copilot wonderful! But I’m worried toId is to generic a name (and it looks like told)… maybe call it toSafeHTMLId() or something better?

@sidvishnoi sidvishnoi changed the title fix(render-biblio): sanitize spaces in reference IDs fix(core/render-biblio): sanitize spaces in reference IDs Apr 16, 2026
Copy link
Copy Markdown
Member

@sidvishnoi sidvishnoi left a comment

Choose a reason for hiding this comment

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

:shipit:

Copy link
Copy Markdown
Member

@sidvishnoi sidvishnoi left a comment

Choose a reason for hiding this comment

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

GitHub asking for review even when I just did, so, :shipit: again.

@marcoscaceres marcoscaceres merged commit 92a3c61 into main Apr 16, 2026
10 checks passed
@marcoscaceres marcoscaceres deleted the fix/biblio-id-spaces branch April 16, 2026 09:48
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.

The names of the reference contain spaces

4 participants