Skip to content

feat(demo-manifest): add stripComments + stripWrappers options#8

Merged
jaysin586 merged 1 commit into
mainfrom
feat/demo-manifest-strip-markers
May 20, 2026
Merged

feat(demo-manifest): add stripComments + stripWrappers options#8
jaysin586 merged 1 commit into
mainfrom
feat/demo-manifest-strip-markers

Conversation

@jaysin586
Copy link
Copy Markdown
Contributor

Summary

Two new opt-in options on demoManifestPlugin for keeping consumer positioning chrome out of the published code panel — without forcing the demo file itself to forgo it.

The use case driving this: svelte-motion's example demos are intrinsically-sized cards (200×120) that need a flex-centering wrapper inside docs-kit's .dk-ex-body so they don't land top-left and let the footer strip float mid-panel. Today that wrapper either has to live on the page side (away from the demo it serves) or pollute the published code with off-topic positioning chrome. With these options it can live in the demo file, marked, and the manifest strips it on emission.

Changes

✨ New options

  • stripComments?: string[] — substring markers whose enclosing comment is removed before highlighting. Catches both /* MARKER */ (block) and <!-- MARKER --> (template). Plain String.includes match, no regex.

  • stripWrappers?: string[] — class tokens whose wrapping element is unwrapped: opening + closing tags vanish, children stay in place as siblings. Also strips the matching CSS rule from the demo's <style> block so the published source doesn't carry orphan selectors. Self-closing matches log a warning (no children to preserve) instead of silently dropping.

Both default to [] (feature off). Consumers opt in per project, e.g.:

demoManifestPlugin({
    stripComments: ['HUMANSPEAK'],
    stripWrappers: ['humanspeak-demo-shell']
})

🔧 Implementation

  • stripMarkedComments() — regex over both comment forms with non-greedy bodies so adjacent comments don't fuse
  • unwrapMarkedElements() — depth-balanced tag matching by tag name (nested same-tag children don't fool the close-tag search). Multi-line attribute layouts tolerated via [^<>]*? against the attrs body
  • stripOrphanCSSRules() — strips rule blocks targeting only the marker class. Compound selectors (.marker, .other) survive intact; @-rules aren't recursed into. Documented limitations in code

Pipeline order matters and is now: comments → wrappers → orphan CSS → existing docs-kit chrome strip → prettier format.

Verification

Smoke-tested by hand against a fixture with nested same-name <div>s, both comment forms, and a mix of orphan + real CSS rules:

  • ✅ Marker comments removed (both forms)
  • ✅ Wrapper element tags removed
  • ✅ Inner <motion.div> preserved
  • ✅ Nested same-tag children preserved (depth balancing works)
  • ✅ Orphan .humanspeak-demo-shell CSS rule removed
  • ✅ Unrelated .real-rule preserved
  • pnpm svelte-check clean
  • pnpm build clean; new options surface in dist/vite/demo-manifest.d.ts

No tests added — this repo doesn't have vitest set up yet, and the existing stripDocsKitChrome heuristic ships untested too. These new helpers follow the same shape and are structured for easy test coverage once we add the infra.

Commits

  • a36be95 feat(demo-manifest): add stripComments + stripWrappers options

Two new opt-in options on `demoManifestPlugin` for keeping consumer
positioning chrome out of the published code panel without forcing
the demo file itself to forgo it:

- `stripComments?: string[]` — substring markers whose enclosing
  comment (`/* … */` block or `<!-- … -->` template) is removed
  before highlighting. Lets consumers leave maintainer notes inside
  demo files explaining *why* the file carries some positioning
  chrome, without leaking that prose into the snippet readers see.
- `stripWrappers?: string[]` — class tokens whose wrapping element
  is unwrapped: opening + closing tags vanish, children stay in
  place as siblings. Also strips the matching CSS rule from the
  demo's `<style>` block so the published source doesn't carry an
  orphan selector pointing at nothing.

Both default to `[]` (feature off). Consumers opt in per-project,
e.g. svelte-motion would pass:

```ts
demoManifestPlugin({
    stripComments: ['HUMANSPEAK'],
    stripWrappers: ['humanspeak-demo-shell']
})
```

Implementation:
- `stripMarkedComments()` — regex over both comment forms
- `unwrapMarkedElements()` — depth-balanced tag matching by tag
  name handles nested same-tag children. Multi-line attribute
  layouts tolerated via `[^<>]*?` against the attrs body. Self-
  closing matches log a warning instead of failing (the marker
  class is almost certainly authored on a wrapping element).
- `stripOrphanCSSRules()` — strips rule blocks targeting only the
  marker class. Compound selectors (`.marker, .other`) survive
  intact; @-rules aren't recursed into. Documented limitations.

Pipeline order (matters):
  comments → wrappers → orphan CSS → existing docs-kit chrome
  strip → prettier format.

Verified by hand against a fixture with nested same-name divs and
both comment forms; all six acceptance checks green. No test infra
in this repo yet — the existing `stripDocsKitChrome` heuristic ships
without tests too, and these helpers follow the same shape.
@jaysin586 jaysin586 added enhancement Apply to new features or improvements to existing features javascript Pull requests that update javascript code labels May 20, 2026
@jaysin586 jaysin586 self-assigned this May 20, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 20, 2026

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

The PR extends the Vite demo-manifest plugin with configurable source-cleanup options. Two new interface fields enable consumers to specify comment markers and wrapper class tokens. Three transformation helpers strip marked comments, unwrap wrapper elements, and remove orphaned CSS. The build pipeline chains these transformations before applying existing docs-kit chrome stripping.

Changes

Demo Manifest Source Cleanup Configuration

Layer / File(s) Summary
Configuration options and resolution
src/lib/vite/demo-manifest.ts
DemoManifestOptions gains stripComments and stripWrappers arrays; ResolvedOptions carries resolved values; resolution logic computes lang de-duplication and option defaults.
String transformation helpers
src/lib/vite/demo-manifest.ts
Three new functions: stripMarkedComments removes block and template comment ranges matching markers; unwrapMarkedElements deletes opening/closing tags for elements whose class contains marker tokens; stripOrphanCSSRules removes <style> rule blocks targeting only wrapper classes.
Manifest build pipeline integration
src/lib/vite/demo-manifest.ts
The manifest display-copy transformation replaces single-pass chrome stripping with an ordered pipeline: strip marked comments → unwrap wrapper elements → remove orphan CSS rules → strip docs-kit chrome → format with prettier.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Three helpers hop through markup bright,
Stripping comments, wrappers out of sight,
Orphan CSS rules take flight,
Pipeline hops through each stage just right!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding two new options (stripComments and stripWrappers) to the demo-manifest plugin.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, explaining the motivation, new options, implementation details, and verification steps.
Docstring Coverage ✅ Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/demo-manifest-strip-markers

Comment @coderabbitai help to get the list of available commands and usage tips.

@jaysin586 jaysin586 merged commit d515dee into main May 20, 2026
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Apply to new features or improvements to existing features javascript Pull requests that update javascript code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant