Repository navigation
feat(markdown): render file trees from an indented filetree fence - #518
Conversation
File trees were written as a ::::tree directive whose body goes through the markdown parser, which strips leading spaces, so every level needed box-drawing connectors and │ pipes to carry its depth. A ```filetree fenced block keeps every leading space, so the tree is now an indented list: one entry per line, children indented further than their parent at any width, no connectors. @docubook/core turns the fence into the Tree component through a new rehypeFileTree plugin in the default rehype pipeline. title="…" or filetree:title becomes the tree's accessible label and is not rendered. The Tree component is rebuilt on a shared column-based parser: mono rows with guide lines, folder and per-type file icons, muted notes after # or //, empty folders from a trailing slash, and the WAI-ARIA tree pattern with the row as the treeitem, explicit levels and positions, arrow keys, Home/End, Enter/Space and a single tab stop. The legacy ::::tree directive and its connectors still render through the same component. The docs move every example to the fence.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
There was a problem hiding this comment.
ℹ️ No critical issues — two minor suggestions inline.
Reviewed changes
Reviewed the whole filetree fence feature in standard mode. The overall assessment is mergeable. The rehypeFileTree placement before the code-title and Prism plugins is correct, the column-based parser handles the documented contract plus legacy connectors (I probed the old docs' Process Example body, mixed connector widths, notes and CRLF), and the PR's own tests pass locally (core 7, markdown 21).
rehypeFileTree(core) — the plugin swapslanguage-filetree[:title]fences for<Tree content title>and reads the title from the shorthand or frompreProcess'scodeTitle.parseFileTree(markdown) — this parser nests entries by the column where each name starts. It accepts any indent width, trailing-slash folders,#///notes and legacy├─/│connectors.TreeMdxrewrite — the component keeps its state flat with path ids, which gives deterministic SSR markup. It follows the WAI-ARIA navigation tree roles with explicit level/setsize/posinset and a roving tab stop. The title becomesaria-labelonly.- Styles and docs — styling moved to
.mdx-tree*instyles.csson the theme variables. The File Tree and formatting docs, the README and a minor changeset for core + markdown are updated.
Top priorities: (1) let modifier-key shortcuts pass through the tree's key handler, (2) optionally reuse the code-fence class lookup instead of copying it a fifth time.
claude-opus-5-5 | 𝕏
The tree's key handler acted on every key and called preventDefault, so with a row focused Alt+Left/Right (back and forward on Windows and Linux) collapsed or expanded a folder instead of navigating, and Ctrl+Home/End were swallowed. Keys pressed with Alt, Ctrl or Meta are now left to the browser, as in the WAI-ARIA tree examples.
…ee plugins rehypeMermaid and rehypeFileTree both swap a fence of one language for a component, and each carried its own copy of the pre > code lookup and className normalisation. Both now use getFenceCode and classListOf from utils. rehypeMermaid had no tests, so the shared helpers and its swap are covered now.
There was a problem hiding this comment.
✅ No new issues found. Both earlier suggestions are fixed cleanly, and I've resolved their threads.
Reviewed changes
Reviewed the two commits pushed since the last Pullfrog review (standard mode). Verdict: READY. At e52ffd7, core passes 134 tests and tsc --noEmit is clean, and the markdown tree suites pass 22 tests.
- Modifier-key guard in
TreeMdx:onKeyDownnow returns beforepreventDefault()when Alt, Ctrl or Meta is held, so shortcuts like Alt+← (back) and Ctrl+Home still reach the browser. A new test checks each modifier and confirms a plain ArrowLeft still collapses the folder. - Shared fence lookup: added
classListOfandgetFenceCodetopackages/core/src/utils.ts, and bothrehypeMermaidandrehypeFileTreenow use them. Mermaid output is unchanged: the class split and text extraction work the same as before, andfenceHelpers.test.tsadds the coverage Mermaid didn't have.
claude-opus-5-5 | 𝕏

Summary
File trees move from the
::::treedirective to a```filetreefenced block whose body is a plain indented list: one entry per line, children indented further than their parent, no connector characters.The directive's body goes through the markdown parser, which strips leading spaces, so every level had to be drawn with
├─/└─connectors and│pipes. A fence keeps every leading space, which is what makes indentation alone enough.Changes
@docubook/corerehypeFileTreeplugin, registered increateDefaultRehypePlugins()right afterrehypeMermaidand exported. It turns<pre><code class="language-filetree">into<Tree content="…">before the code-title and Prism plugins see it.title="…"(read bypreProcess) or thefiletree:titleshorthand becomes thetitleprop.@docubook/markdownutils/fileTree.ts: a parser that nests by the column where each name starts, so any indent width works (two spaces, four, tabs as four, uneven widths). A trailing/marks a folder, so an empty folder keeps its icon. Text after#or//becomes a note. Connectors are still accepted because the legacy directive depends on them; the fence does not document them.TreeMdxrebuilt:titleis the tree'saria-labelfor screen readers, defaulting to "File tree", and is not drawn.treeitemandliisrole="none", so each item's accessible name is exactly its row. Items carry explicitaria-level,aria-setsizeandaria-posinset.styles.css(.mdx-tree*) on the existing theme variables, so dark mode follows.::::treedirective still renders through the same component, so existing content keeps working in this minor release.Docs
components/file-tree.mdxis rewritten around the indentation contract, with sections on folders, notes, the screen reader label, keyboard support and the legacy directive.getting-started/formatting.mdxand the v1 migration table now point to the fence.Changeset: minor for
@docubook/coreand@docubook/markdown.Verification
@docubook/coretestsserializeend-to-end fortitle=andfiletree:title@docubook/markdowntests@docubook/flameteststest:release-plan/docs/components/file-tree