Skip to content

feat(markdown): render file trees from an indented filetree fence - #518

Merged
gitfromwildan merged 3 commits into
mainfrom
feat/markdown-filetree-fence
Nov 10, 2026
Merged

gitfromwildan merged 3 commits into
mainfrom
feat/markdown-filetree-fence

Conversation

@gitfromwildan

Copy link
Copy Markdown
Member

Summary

File trees move from the ::::tree directive to a ```filetree fenced block whose body is a plain indented list: one entry per line, children indented further than their parent, no connector characters.

```filetree title="Project layout"
my-app/
  src/
    App.tsx          # entry point
    components/
      Button.tsx
  package.json
```

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/core

  • New rehypeFileTree plugin, registered in createDefaultRehypePlugins() right after rehypeMermaid and exported. It turns <pre><code class="language-filetree"> into <Tree content="…"> before the code-title and Prism plugins see it.
  • title="…" (read by preProcess) or the filetree:title shorthand becomes the title prop.

@docubook/markdown

  • utils/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.
  • TreeMdx rebuilt:
    • Renders only the tree: a thin bordered panel with mono rows and guide lines. There is no code-block header, copy button or visible title.
    • Rows get open/closed folder icons and per-type file icons (code, JSON, Markdown, image, config, lock).
    • title is the tree's aria-label for screen readers, defaulting to "File tree", and is not drawn.
    • Accessibility follows the WAI-ARIA navigation tree pattern. The row is the treeitem and li is role="none", so each item's accessible name is exactly its row. Items carry explicit aria-level, aria-setsize and aria-posinset.
    • Keyboard: arrows, Home/End and Enter/Space, with a single roving tab stop.
    • Everything starts expanded, so the server-rendered HTML shows the whole tree without JavaScript.
  • Styles live in styles.css (.mdx-tree*) on the existing theme variables, so dark mode follows.
  • The legacy ::::tree directive still renders through the same component, so existing content keeps working in this minor release.

Docs

  • components/file-tree.mdx is rewritten around the indentation contract, with sections on folders, notes, the screen reader label, keyboard support and the legacy directive.
  • getting-started/formatting.mdx and the v1 migration table now point to the fence.

Changeset: minor for @docubook/core and @docubook/markdown.

Verification

Check Result
@docubook/core tests 128 pass, including the plugin unit tests and serialize end-to-end for title= and filetree:title
@docubook/markdown tests 146 pass, including the indentation contract tests and the legacy directive
@docubook/flame tests 876 pass
typecheck, oxlint, test:release-plan clean
Built docs site, checked in Chromium click, keyboard, light, dark and 390px mobile all work, with no console errors and no horizontal overflow
Lighthouse accessibility on /docs/components/file-tree no findings on the tree; the remaining findings (sidebar contrast, logo alt) come from the Flame docs theme and predate this PR

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.
@vercel

vercel Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docu Ignored Ignored Preview Nov 10, 2026 4:06am UTC

@gitfromwildan gitfromwildan self-assigned this Nov 10, 2026

@pullfrog pullfrog Bot 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.

ℹ️ 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 swaps language-filetree[:title] fences for <Tree content title> and reads the title from the shorthand or from preProcess's codeTitle.
  • 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.
  • TreeMdx rewrite — 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 becomes aria-label only.
  • Styles and docs — styling moved to .mdx-tree* in styles.css on 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.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using 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.

@pullfrog pullfrog Bot 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.

✅ 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: onKeyDown now returns before preventDefault() 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 classListOf and getFenceCode to packages/core/src/utils.ts, and both rehypeMermaid and rehypeFileTree now use them. Mermaid output is unchanged: the class split and text extraction work the same as before, and fenceHelpers.test.ts adds the coverage Mermaid didn't have.

Pullfrog  | View workflow run | Using claude-opus-5-5 | 𝕏

@gitfromwildan
gitfromwildan merged commit 791c63c into main Nov 10, 2026
15 checks passed
@gitfromwildan
gitfromwildan deleted the feat/markdown-filetree-fence branch November 10, 2026 04:20
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