Skip to content

fix(core/exporter): strip toc-inline class from exports#5244

Open
marcoscaceres wants to merge 3 commits intomainfrom
fix/4771-toc-inline
Open

fix(core/exporter): strip toc-inline class from exports#5244
marcoscaceres wants to merge 3 commits intomainfrom
fix/4771-toc-inline

Conversation

@marcoscaceres
Copy link
Copy Markdown
Contributor

Closes #4771

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

This PR addresses nondeterministic exported HTML by ensuring ReSpec’s exporter removes ToC layout classes (toc-inline, toc-sidebar) from the <body> during export, preventing them from leaking into static builds (fixing #4771).

Changes:

  • Strip toc-inline in addition to toc-sidebar from body.classList during export cleanup.
  • Add a spec test to verify exported HTML does not contain those body classes.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/core/exporter.js Extends export cleanup to remove toc-inline along with toc-sidebar from <body>.
tests/spec/core/exporter-spec.js Adds coverage ensuring exported HTML output doesn’t include toc-inline/toc-sidebar on <body>.

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

Comment thread tests/spec/core/exporter-spec.js Outdated
@marcoscaceres
Copy link
Copy Markdown
Contributor Author

@copilot Can you confirm all your feedback has been addressed? Can you fix anything that was not addressed?

Copilot AI and others added 2 commits May 4, 2026 13:20
Agent-Logs-Url: https://github.com/speced/respec/sessions/3a8c6d27-b065-491f-a30e-1ea67348a871

Co-authored-by: marcoscaceres <870154+marcoscaceres@users.noreply.github.com>
…ositives

Agent-Logs-Url: https://github.com/speced/respec/sessions/3a8c6d27-b065-491f-a30e-1ea67348a871

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

Copilot AI commented May 4, 2026

@copilot Can you confirm all your feedback has been addressed? Can you fix anything that was not addressed?

All the feedback has been addressed. The one remaining issue from the original review was the concern about the regex defaulting to "" on no match, which could hide failures if serialization changes. I've updated the test (commit c6acee6) to:

  1. Match the entire body opening tag /<body[^>]*>/ and explicitly assert it exists (expect(bodyTag).toBeTruthy()), so the test will fail if the body tag is missing rather than silently passing.
  2. Scope the class checks to within the class attribute using word-boundary patterns (/\bclass="[^"]*\btoc-inline\b/), which avoids false positives from other attributes containing those strings.

The raw HTML string approach (rather than getExportedDoc()) is preserved as you noted it's intentional — it validates the actual serialized artifact rather than a re-parsed live DOM.

@marcoscaceres
Copy link
Copy Markdown
Contributor Author

@copilot Can you confirm all your feedback has been addressed? Can you fix anything that was not addressed?

Copy link
Copy Markdown
Contributor

Copilot AI commented May 8, 2026

@copilot Can you confirm all your feedback has been addressed? Can you fix anything that was not addressed?

All feedback is addressed. The PR currently has:

  1. src/core/exporter.js — strips both toc-inline and toc-sidebar from body.classList on export.
  2. tests/spec/core/exporter-spec.js (commit c6acee6) — the test:
    • Matches the full <body> opening tag and asserts it's present, so a serialization format change won't silently pass
    • Scopes the class checks to within the class attribute using word-boundary patterns (/\bclass="[^"]*\btoc-inline\b/) to avoid false positives from other attributes

No further changes are needed.

@marcoscaceres marcoscaceres marked this pull request as ready for review May 9, 2026 02:40
@marcoscaceres marcoscaceres requested a review from sidvishnoi May 9, 2026 02:40
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.

Randomly appearing class "toc-inline" in body element

4 participants