refactor(website): simplify docs subtree (palette / sidebar / markdown / nav) by Jocs · Pull Request #4349 · marktext/marktext · GitHub
Skip to content

refactor(website): simplify docs subtree (palette / sidebar / markdown / nav) - #4349

Merged
Jocs merged 1 commit into
developfrom
simplify/website-docs
Jun 2, 2026
Merged

Jocs merged 1 commit into
developfrom
simplify/website-docs

Conversation

@Jocs

@Jocs Jocs commented Jun 2, 2026

Copy link
Copy Markdown
Member

Summary

Internal cleanups to the /docs subtree. No behavior changes for readers — keyboard shortcuts, navigation, search, the sidebar collapse, and rendered output are all the same. Smaller bundle / fewer surprises for editors.

  • CommandPalette: drop the hitsRef / selectedRef "mirror state into a ref" pattern; the keydown handler reads hits and setSelected((s) => …) directly. Fix the O(n²) hits.indexOf(hit) inside the group render by attaching the original index in groupHits. Escape page.hint — only body-match snippets carry HTML; everything else renders as text.
  • docs-search: cache the lowercased title / group / hint / body / headings per page in a WeakMap, so scorePage stops re-lowercasing the same fields on every keystroke.
  • SidebarContext: lift sidebarOpen / setSidebarOpen into DocsChrome and consume it from DocsSidebar + SidebarToggle. Drops the document.getElementById('docSide') reach-in (and the unused onNavigate prop).
  • DocsChrome: remove the document.body.classList.add('docs') side effect; the .docs class now lives on a server-rendered wrapper. docs.css updated to match (body.docs → .docs).
  • docs-nav: build PAGE_BY_KEY once at module load; findPageBySlug and neighborsFor are O(1) lookups instead of slug.join('/') scans on every call.
  • markdown.ts: type AlertKind = 'note' | 'tip' | 'warn', plus an ALERT_ICON_PATHS lookup table that replaces the three-level ternary in calloutIcon. Skip rewriteHref + link class on the rehype-autolink-headings anchor so its #id href stays untouched.

Test plan

  • pnpm --filter marktext-website type-check
  • pnpm --filter marktext-website lint
  • pnpm --filter marktext-website build (37 static pages, no runtime errors)
  • CI

🤖 Generated with Claude Code

…n / nav)

- CommandPalette: drop hitsRef/selectedRef mirroring, fix O(n²) hits.indexOf
  by attaching the original index in groupHits, and escape page.hint —
  only body-match snippets carry HTML.
- docs-search: cache lowercased title/group/hint/body/headings per page in
  a WeakMap so scorePage stops lowercasing the same fields every keystroke.
- SidebarContext: lift the open/closed flag into DocsChrome and consume it
  from DocsSidebar + SidebarToggle, dropping the
  document.getElementById('docSide') reach-in and the unused onNavigate prop.
- DocsChrome: remove the document.body.classList side-effect; the .docs
  class now lives on a server-rendered wrapper, with docs.css updated to
  match.
- docs-nav: introduce PAGE_BY_KEY map; findPageBySlug and neighborsFor
  become O(1) lookups instead of repeated slug.join scans.
- markdown.ts: type AlertKind ('note'|'tip'|'warn') and replace the
  three-level ternary on the callout SVG path with an ALERT_ICON_PATHS
  table; skip rewriteHref / 'link' class on the rehype-autolink-headings
  anchor so its href stays untouched.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Build artifacts for PR #4349:

Run: https://github.com/marktext/marktext/actions/runs/26832194530

Artifact Size Link
marktext-windows-arm64 270.6 MB Download
marktext-macos-x64 271.7 MB Download
marktext-linux 592.9 MB Download
marktext-windows-x64 271.9 MB Download
marktext-macos-arm64 261.4 MB Download

@Jocs
Jocs merged commit 8544b10 into develop Jun 2, 2026
11 checks passed
@Jocs
Jocs deleted the simplify/website-docs branch June 10, 2026 07:08
thimbleberrysystems pushed a commit to thimbleberrysystems/WordBird that referenced this pull request Jun 21, 2026
…n / nav) (marktext#4349)

- CommandPalette: drop hitsRef/selectedRef mirroring, fix O(n²) hits.indexOf
  by attaching the original index in groupHits, and escape page.hint —
  only body-match snippets carry HTML.
- docs-search: cache lowercased title/group/hint/body/headings per page in
  a WeakMap so scorePage stops lowercasing the same fields every keystroke.
- SidebarContext: lift the open/closed flag into DocsChrome and consume it
  from DocsSidebar + SidebarToggle, dropping the
  document.getElementById('docSide') reach-in and the unused onNavigate prop.
- DocsChrome: remove the document.body.classList side-effect; the .docs
  class now lives on a server-rendered wrapper, with docs.css updated to
  match.
- docs-nav: introduce PAGE_BY_KEY map; findPageBySlug and neighborsFor
  become O(1) lookups instead of repeated slug.join scans.
- markdown.ts: type AlertKind ('note'|'tip'|'warn') and replace the
  three-level ternary on the callout SVG path with an ALERT_ICON_PATHS
  table; skip rewriteHref / 'link' class on the rehype-autolink-headings
  anchor so its href stays untouched.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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