Fold and unfold sections of VS Code's Markdown preview at every heading level, # through ######, the way you fold them in the editor.
Features
A fold chevron beside every heading in the preview. It appears when you point at the heading, and stays on folded headings, like the editor's folding controls.
Nested folding. Folding a section hides everything up to the next heading of the same or a higher level, subsections included. Sections you folded inside it stay folded when you open it again.
Shift+click a chevron to fold or unfold a section and every section inside it.
⋯ after a folded heading. Click it to unfold.
Fold All, Unfold All and Fold Level 1–6, from the preview's right-click menu, the Command Palette, or the editor's folding shortcuts while the preview is focused.
Folds are remembered for each file, while you edit, when the preview switches between files, and after you close the preview or restart VS Code.
Find in the preview (Ctrl+F, ⌘F on macOS) searches folded sections too, and opens the ones around a match.
Scroll sync still works: moving through a folded section in the editor brings its heading into view in the preview.
Keyboard accessible: the chevrons are buttons. Tab to one and press Enter or Space.
The same commands are in the preview's right-click menu, with Fold Level as a submenu. Fold Level n folds every heading at that level and leaves other folds as they are.
From the Command Palette, a command applies to the preview of the Markdown file you're editing, or, if a preview is active, to the preview you used last.
Good to know
Needs VS Code 1.108 or later.
Only top-level headings fold. Headings inside block quotes, lists or raw HTML don't get a chevron.
Fold All, Unfold All and Fold Level briefly reload the preview: VS Code doesn't let extensions send messages to its built-in preview, so the command reaches it through a fresh render. Folding with the chevrons doesn't reload anything.
Folds are stored by heading text. Renaming a folded heading while its preview is open keeps it folded; renaming it while the preview is closed unfolds it.
Folds are stored in the preview's own browser storage, on your machine. The side preview (Markdown: Open Preview to the Side) and the preview editor (View: Reopen Editor With… → Markdown Preview) keep separate folds.
Folding the preview doesn't fold the editor, or the other way round: VS Code doesn't tell extensions what's folded in the editor.