Skip to content

chore(docs): improve writing, add troubleshooting guide - #5409

Open
fb55 wants to merge 3 commits into
mainfrom
docs-revamp
Open

chore(docs): improve writing, add troubleshooting guide#5409
fb55 wants to merge 3 commits into
mainfrom
docs-revamp

Conversation

@fb55

@fb55 fb55 commented Aug 6, 2026

Copy link
Copy Markdown
Member

And a security overview

@fb55
fb55 requested a lite review from Copilot August 6, 2026 13:36
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@fb55, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 11 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 1afa9ac5-8bce-4047-be22-87473b24f7ac

📥 Commits

Reviewing files that changed from the base of the PR and between a75fe47 and 7db04a4.

📒 Files selected for processing (13)
  • website/src/components/Sidebar.astro
  • website/src/components/live-code.tsx
  • website/src/content/docs/advanced/configuring-cheerio.md
  • website/src/content/docs/advanced/security.md
  • website/src/content/docs/basics/extract.mdx
  • website/src/content/docs/basics/loading.md
  • website/src/content/docs/basics/manipulation.md
  • website/src/content/docs/basics/selecting.mdx
  • website/src/content/docs/basics/troubleshooting.mdx
  • website/src/content/docs/intro.md
  • website/src/layouts/DocsLayout.astro
  • website/src/lib/docs-nav.ts
  • website/src/plugins/remark-live-code.ts
📝 Walkthrough

Summary by CodeRabbit

  • New Features
    • Added interactive “Edit & run” examples with syntax highlighting, execution controls, console output, and error feedback.
    • Added new guidance for data extraction, troubleshooting, security, and CSS selectors.
  • Documentation
    • Reorganized the getting-started, loading, manipulation, traversal, parser configuration, and extension guides.
    • Improved explanations of encoding, URL handling, parsing, selectors, and content manipulation.
    • Added a redirect for the relocated extraction guide.
  • Bug Fixes
    • Clarified that empty() removes child elements, text, and comments while preserving the selected element.

Walkthrough

The PR refreshes the Cheerio documentation, relocates extraction guidance, adds security and troubleshooting pages, updates navigation, and introduces lazy-loaded Sandpack editors for live examples.

Changes

Documentation and interactive examples

Layer / File(s) Summary
Basics guides and API explanations
src/api/manipulation.ts, website/src/content/docs/intro.md, website/src/content/docs/basics/*
Updated introductory, loading, selecting, traversing, manipulation, and troubleshooting guidance. Added the extraction, selecting, and troubleshooting pages.
Advanced guides and documentation routing
website/src/content/docs/advanced/*, website/src/components/Sidebar.astro, website/astro.config.mjs
Updated parser and extension guides. Added security guidance. Moved extraction documentation under Basics and added navigation and redirect changes.
On-demand live example editor
website/src/components/live-code.tsx, website/src/components/sandpack-editor.tsx, website/src/plugins/remark-live-code.ts, website/src/env.d.ts, website/astro.config.mjs
Preserved highlighted code by default and loads the Sandpack editor after “Edit & run.” The editor supports run, reset, close, console output, syntax errors, and the injected Cheerio version.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Reader
  participant LiveCode
  participant SandpackEditor
  participant Sandpack
  Reader->>LiveCode: Click Edit & run
  LiveCode->>SandpackEditor: Lazy-load editor
  SandpackEditor->>Sandpack: Create Cheerio workspace
  Reader->>SandpackEditor: Run or reset code
  SandpackEditor->>Sandpack: Update /index.js or restore files
  Sandpack-->>SandpackEditor: Console output or syntax errors
  Reader->>LiveCode: Click Close
Loading

Suggested reviewers: copilot

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main documentation improvements and the addition of a troubleshooting guide.
Description check ✅ Passed The description identifies the security overview, which is a documented part of the changeset.
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.
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch docs-revamp

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The review found a couple of correctness/clarity issues in the updated docs/plugin behavior that should be fixed before merging.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Pull request overview

This PR updates the documentation site content and live-code UX: it rewrites several guides, adds new “Troubleshooting” and “Security” pages, moves the extract guide into Basics (with redirects), and changes the live-code rendering so readers see a static highlighted block until they opt into loading the Sandpack editor.

Changes:

  • Add new docs pages for Selecting Elements, Extracting Data, Troubleshooting, and Security; refresh existing intro/basics/advanced writing.
  • Update live-code remark/plugin + React components to preserve the highlighted code block as LiveCode children and lazy-load Sandpack only when editing.
  • Pin Sandpack’s cheerio dependency to the repo’s package version via a Vite-defined constant and add an Astro redirect for the moved extract page.
File summaries
File Description
website/src/plugins/remark-live-code.ts Wrap ```… live fences in LiveCode while preserving the code block as a child.
website/src/env.d.ts Add a global TS declaration for __CHEERIO_VERSION__.
website/src/content/docs/intro.md Rewrite introduction copy and restructure onboarding narrative.
website/src/content/docs/basics/troubleshooting.mdx Add a new troubleshooting guide with live examples.
website/src/content/docs/basics/traversing.mdx Rewrite traversal guide intro/outro and adjust section structure.
website/src/content/docs/basics/selecting.mdx Add a new selecting guide (MDX + live examples).
website/src/content/docs/basics/selecting.md Remove old selecting guide (replaced by MDX version).
website/src/content/docs/basics/manipulation.md Rewrite manipulation guide prose and examples; add clarifications.
website/src/content/docs/basics/loading.md Rewrite loading guide and expand fromURL behavior + request customization docs.
website/src/content/docs/basics/extract.mdx Add extract guide under Basics with live examples.
website/src/content/docs/advanced/security.md Add a new security overview page.
website/src/content/docs/advanced/extract.md Remove old advanced extract page (moved to Basics).
website/src/content/docs/advanced/extending-cheerio.md Rewrite/clarify extension points and TypeScript guidance.
website/src/content/docs/advanced/configuring-cheerio.md Rewrite parser/configuration explanations and examples.
website/src/components/Sidebar.astro Add new sidebar entries and move extract from Advanced to Basics; add Security.
website/src/components/sandpack-editor.tsx New extracted Sandpack editor component with toolbar and dynamic sizing.
website/src/components/live-code.tsx Lazy-load Sandpack editor and render a static highlighted block until editing.
website/astro.config.mjs Define __CHEERIO_VERSION__ from root package.json; add redirect for moved extract.
src/api/manipulation.ts Clarify empty() JSDoc to match behavior on non-container nodes.
Review details
  • Files reviewed: 18/19 changed files
  • Comments generated: 2
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Comment on lines +193 to +195
Supplying `requestOptions` discards the defaults entirely, so you must include
`method` yourself — omitting it fails with `method must be a string`. Custom
`headers` likewise replace the default `Accept` header rather than adding to it.
Comment thread website/src/plugins/remark-live-code.ts Outdated
* see until they ask for an editor — no Sandpack, no third-party bundler,
* and it still renders without JavaScript.
*/
node.meta = null;

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 7

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
website/src/plugins/remark-live-code.ts (1)

29-53: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Preserve code-fence metadata other than live.

Line 35 deletes all metadata. A fence such as ```js live {2} title="example.js" loses its title and line-highlight configuration before the normal code renderer processes the preserved child. Remove only the standalone live marker.

Proposed fix
-  node.meta = null;
+  node.meta =
+    node.meta?.replace(/(^|\s)live(?=\s|$)/, '$1').trim() || null;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@website/src/plugins/remark-live-code.ts` around lines 29 - 53, Update the
metadata handling in the remark-live-code transformation to remove only the
standalone live marker while preserving other fence metadata such as language,
line highlighting, and title for the child code node. Replace the blanket
assignment in the LiveCode wrapping logic without changing the existing code and
JSX node behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@website/src/components/live-code.tsx`:
- Around line 41-50: Update the JSX in the LiveCode component so the “Edit &
run” button no longer uses absolute positioning over children. Place it in
normal document flow above the code block, preserving its existing styling and
click behavior.

In `@website/src/content/docs/advanced/configuring-cheerio.md`:
- Around line 133-141: Update the `.load()` example to define a valid markup
string and `htmlparser2` parser options before calling
`htmlparser2.parseDocument`; pass those defined values into `parseDocument` so
the example runs in Node and still demonstrates loading an already-parsed
document.

In `@website/src/content/docs/advanced/security.md`:
- Around line 29-33: Update the security guidance around scraped markup and
`text()` output to state that removing markup does not make untrusted text
universally safe. Instruct users to assign untrusted text through `textContent`
or escape it for the intended output context, while retaining the sanitizer
guidance for rendered markup.
- Around line 52-62: Update the “Selectors built from user input” documentation
to prohibit interpolating untrusted values even inside quoted attribute
selectors. Replace the interpolated-selector example with a fixed selector that
reads the attribute value and compares it as data, and retain guidance that user
input must not become selector syntax.

In `@website/src/content/docs/basics/manipulation.md`:
- Around line 103-107: Update the warning in the text() documentation to
describe prop('innerText') as tree-based extraction that omits script and style
content without applying CSS layout or visibility rules. Replace the
reader-visible wording while preserving the existing contrast with raw
textContent.

In `@website/src/content/docs/basics/troubleshooting.mdx`:
- Around line 138-144: Update the robust selector example to escape id according
to CSS string rules before interpolation, covering double quotes, backslashes,
and newlines; alternatively, avoid selector interpolation by selecting a broader
set and comparing the id attribute with .filter().

In `@website/src/content/docs/intro.md`:
- Around line 74-82: Update the DOM traversal example near the “Traversing the
DOM” section so the chained selector operates on markup that contains a matching
`.subtitle` descendant. Either add a `.subtitle` element under the existing
`h2.title` fixture and select its parent before calling `find()`, or change the
example selector to match the document loaded earlier, while preserving the
demonstration of traversal returning a match.

---

Outside diff comments:
In `@website/src/plugins/remark-live-code.ts`:
- Around line 29-53: Update the metadata handling in the remark-live-code
transformation to remove only the standalone live marker while preserving other
fence metadata such as language, line highlighting, and title for the child code
node. Replace the blanket assignment in the LiveCode wrapping logic without
changing the existing code and JSX node behavior.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a00fcbf6-d020-40d4-b179-685501789036

📥 Commits

Reviewing files that changed from the base of the PR and between 8ee89b5 and a75fe47.

📒 Files selected for processing (19)
  • src/api/manipulation.ts
  • website/astro.config.mjs
  • website/src/components/Sidebar.astro
  • website/src/components/live-code.tsx
  • website/src/components/sandpack-editor.tsx
  • website/src/content/docs/advanced/configuring-cheerio.md
  • website/src/content/docs/advanced/extending-cheerio.md
  • website/src/content/docs/advanced/extract.md
  • website/src/content/docs/advanced/security.md
  • website/src/content/docs/basics/extract.mdx
  • website/src/content/docs/basics/loading.md
  • website/src/content/docs/basics/manipulation.md
  • website/src/content/docs/basics/selecting.md
  • website/src/content/docs/basics/selecting.mdx
  • website/src/content/docs/basics/traversing.mdx
  • website/src/content/docs/basics/troubleshooting.mdx
  • website/src/content/docs/intro.md
  • website/src/env.d.ts
  • website/src/plugins/remark-live-code.ts
💤 Files with no reviewable changes (2)
  • website/src/content/docs/advanced/extract.md
  • website/src/content/docs/basics/selecting.md

Comment thread website/src/components/live-code.tsx Outdated
Comment thread website/src/content/docs/advanced/configuring-cheerio.md
Comment thread website/src/content/docs/advanced/security.md Outdated
Comment thread website/src/content/docs/advanced/security.md
Comment thread website/src/content/docs/basics/manipulation.md Outdated
Comment thread website/src/content/docs/basics/troubleshooting.mdx
Comment thread website/src/content/docs/intro.md
- Fix selector-injection advice in the security and troubleshooting
  guides. Interpolating a value into a quoted attribute selector is not
  safe: a `"` in the value closes the attribute and injects new selector
  syntax. Recommend matching on a fixed selector and comparing the
  attribute as data instead.
- Stop calling `text()` output safe. It strips markup structure but can
  still contain `<`, `>` and `"`, which rebuild markup in an HTML sink.
- Correct `prop('innerText')`: it skips script and style content, but
  applies no CSS, so `display: none` content is still included.
- Derive the sidebar and the prev/next pager from one shared module.
  The two lists had drifted, leaving the new pages with no pagination
  and a dead link to the old extract URL.
- Add an error boundary around the lazily loaded editor, so a failed
  chunk falls back to the static code block instead of unmounting it.
- Move the "Edit & run" button out of the code block's top-right corner,
  where it could cover a long line, into a bar above it.
- Note that some browser-only pseudo-classes throw rather than matching
  nothing, and soften the claim about css-select's pseudo-class support.
- Make the intro `find()` example and the htmlparser2 `parseDocument`
  example actually runnable.
- Document `requestOptions` precisely: `headers` is overridden only when
  supplied, but `method` is never defaulted.
- Strip only the `live` token from code fence meta, not all of it.
Copilot AI review requested due to automatic review settings August 6, 2026 14:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new redirect only covers /docs/advanced/extract and should also redirect /docs/advanced/extract/ to avoid breaking existing trailing-slash links.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Review details

Suppressed comments (1)

website/astro.config.mjs:29

  • The redirect keeps the old advanced/extract URL working, but it only covers the no-trailing-slash form. The docs navigation and canonical links use trailing slashes (e.g. /docs/advanced/extract/), so existing inbound links may still 404 unless that variant is redirected too.
  // `extract` moved from Advanced to Basics; keep the published URL working.
  redirects: {
    '/docs/advanced/extract': '/docs/basics/extract/',
  },
  • Files reviewed: 20/21 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Copilot AI review requested due to automatic review settings August 6, 2026 14:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new redirect for the moved Extract page likely misses the trailing-slash URL that was previously published and may cause a 404 for existing links.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Review details

Suppressed comments (1)

website/astro.config.mjs:29

  • The redirect keeps /docs/advanced/extract working, but the previously published sidebar URL used a trailing slash (/docs/advanced/extract/). With the current config, that variant may not redirect and could 404 depending on Astro’s route normalization/trailing-slash settings. Add an explicit redirect for the trailing-slash path as well.
  // `extract` moved from Advanced to Basics; keep the published URL working.
  redirects: {
    '/docs/advanced/extract': '/docs/basics/extract/',
  },
  • Files reviewed: 20/21 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants