Skip to content

fix(search): preserve literal code block content in index - #2816

Open
xu91102 wants to merge 1 commit into
docsifyjs:developfrom
xu91102:fix/search-code-block-content
Open

xu91102 wants to merge 1 commit into
docsifyjs:developfrom
xu91102:fix/search-code-block-content

Conversation

@xu91102

@xu91102 xu91102 commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Summary

HTML examples inside fenced or indented code blocks can disappear from the search index. genIndex() passes their already-lexed text through the Markdown parser again, which treats tags as HTML and removes them.

Keep code-token text as literal content when building the index. Other tokens retain their existing conversion, and search results still use the existing HTML escaping. Regression tests cover a code block immediately after a heading, after paragraph text, at the start of a page without a heading, and an indented code block. They also verify that the HTML example is displayed as text rather than inserted as an element.

To reproduce on a fresh page with the search plugin enabled:

# Code examples

```html
<customwidget />
```

Search for customwidget. Before this change there is no result; after it, the result includes the literal <customwidget /> example.

Related issue, if any:

Reproduced on develop at d823dbe51c1b2dea4c2091e2b952ded0d1e16616; no matching open fix found.

What kind of change does this PR introduce?

  • Bugfix

For any code change,

  • Related documentation has been updated, if needed (no public API change)
  • Related tests have been added or updated

Does this PR introduce a breaking change?

  • No

Validation

  • Confirmed the new browser regression fails before the fix because the result is missing, then passes after the fix.
  • npm run build: passed.
  • npm run lint: passed.
  • npm run typecheck: passed.
  • npm run test:jest -- --runInBand: 128 tests and 46 snapshots passed.
  • npm run test:e2e:chromium -- test/e2e/search.test.js --workers=2 --reporter=line: all 23 search-plugin tests passed.

Browser coverage: Chromium via Playwright. Firefox, WebKit, and the full unrelated E2E suite were not run locally.

Developed with assistance from OpenAI Codex; the regression and fix were validated locally.

@vercel

vercel Bot commented Sep 28, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the Docsify Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
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.

1 participant