展示 HN: leaf – 一个具有 GUI 般体验的终端 Markdown 预览器
Show HN: leaf – a terminal Markdown previewer with a GUI-like experience

原始链接: https://github.com/RivoLink/leaf

## Leaf:一个终端 Markdown 预览器 Leaf 是一个命令行工具,用于以类似 GUI 的体验预览 Markdown 文件。它适用于 macOS、Linux、Android/Termux 和 Windows。安装可以通过 shell 脚本(macOS/Linux/Android)或 PowerShell(Windows),或通过 npm 轻松完成。更新可以使用 `leaf --update` 或 `npm update -g @rivolink/leaf` 进行管理。 **主要特性:** * **预览:** 直接打开文件 (`leaf TESTING.md`) 或使用模糊/目录选择器 (`leaf --picker`)。 监听模式 (`leaf --watch`) 会在保存时自动重新加载。 * **渲染:** 支持语法高亮、Unicode 表格、TOC 侧边栏、LaTeX 数学公式和常见的 Markdown 元素(粗体、斜体、列表等)。 * **输入:** 接受来自文件、stdin(管道)或生成内容的 Markdown。 * **导航与搜索:** 提供键盘快捷键用于滚动、搜索和打开文件/编辑器。 * **自定义:** 包括主题选择器和编辑器选项。 对于 Windows 用户,请确保已安装最新的 Visual C++ Redistributable,并在更新期间通过关闭现有的 Leaf 实例并重新运行安装程序来解决潜在的文件锁定问题。 [https://github.com/RivoLink/leaf](https://github.com/RivoLink/leaf)

对不起。
相关文章

原文

leaf

Terminal Markdown Previewer — GUI-like experience.

Install the latest published binary.

macOS / Linux / Android / Termux:

curl -fsSL https://raw.githubusercontent.com/RivoLink/leaf/main/scripts/install.sh | sh

Windows:

irm https://raw.githubusercontent.com/RivoLink/leaf/main/scripts/install.ps1 | iex

npm:

npm install -g @rivolink/leaf

Verify the installation:

Update an existing installation to the latest published release.

Self:

leaf --update downloads the matching published asset, verifies it against the published checksums.txt SHA256, and then installs it.

On Windows, if replacing the running .exe is blocked by the OS, rerun the PowerShell installer from the install section.

npm:

npm update -g @rivolink/leaf

Clone the repository:

git clone https://github.com/RivoLink/leaf.git
cd leaf

Build the release binary locally:

Create a local bin directory if needed and symlink leaf into it:

mkdir -p ~/.local/bin
ln -sf "$(pwd)/target/release/leaf" ~/.local/bin/leaf

If ~/.local/bin is not already on your PATH, add it to ~/.bashrc or ~/.zshrc:

export PATH="$HOME/.local/bin:$PATH"
# Open a Markdown file
leaf TESTING.md

# Watch mode — reloads automatically on save
leaf --watch TESTING.md
leaf -w TESTING.md

# Open the fuzzy Markdown picker
leaf

# Open the classic directory browser picker
leaf --picker

# Open the fuzzy Markdown picker, then watch the selected file
leaf -w

# Open the classic directory browser picker, then watch the selected file
leaf -w --picker

# Open a dash-prefixed filename
leaf -- -notes.md

# Stream Markdown from another CLI tool
claude "explain Rust lifetimes" | leaf

# Preview a local file through stdin
cat TESTING.md | leaf
Key Action
j / Scroll down
k / Scroll up
d / PgDn Page down (20 lines)
u / PgUp Page up (20 lines)
g / Home Top
G / End Bottom
t Toggle TOC sidebar
Shift+Sel Select text
Shift+T Open theme picker
Shift+E Open editor picker
Shift+P Open file browser
Ctrl+E Open in editor
Ctrl+P Open fuzzy picker
Ctrl+F / / Find
n / N Next / prev match
? Show help popup
r Force reload (watch mode)
q Quit
  • Watch mode --watch / -w — reloads every 250ms, with ⟳ reloaded flash feedback
  • leaf --watch can start from the picker and begin watching after file selection
  • ✅ Syntax highlighting with common language aliases like py, cpp, json, toml, ps1, and dockerfile
  • ✅ Unicode box-drawing tables with left / center / right alignment
  • ✅ TOC sidebar with active section tracking and two-level navigation
  • ✅ Search with match highlighting, /, Ctrl+F, and n / N
  • ✅ Code blocks ┌─ lang ───┐
  • ✅ LaTeX math rendering — inline $...$ and display $$...$$ with Unicode conversion via unicodeit
  • ✅ LaTeX code blocks ```latex / ```tex rendered as formula blocks
  • ✅ Bold, italic, strikethrough, blockquotes, lists, and horizontal rules
  • ✅ YAML frontmatter is ignored in both preview and TOC
  • ✅ Native stdin input with bounded size
  • leaf --update to fetch, verify via published SHA256, and install the latest release on supported platforms
  • ✅ Fuzzy Markdown picker when launched without a file, or anytime with Ctrl+P
  • ✅ Classic directory browser picker with leaf --picker, or anytime with Shift+P
  • ✅ Theme picker with runtime preview
  • ✅ Help popup with in-app shortcuts
# Terminal 1: generate the file
aichat "..." > notes.md

# Terminal 2: live watch
leaf --watch notes.md

Windows: missing Visual C++ runtime

If leaf.exe does not start on Windows and reports a missing MSVC runtime, install the latest supported Microsoft Visual C++ Redistributable from Microsoft Learn:

Direct download for the latest supported X64 Microsoft Visual C++ Redistributable:

For leaf-windows-x86_64.exe, the relevant package is the latest supported X64 Visual C++ v14 Redistributable.

Windows: update or file replacement error

If leaf --update fails on Windows with an error about replacing, renaming, or writing leaf.exe, the running executable was likely locked by the OS.

Close any terminal session still running leaf, then rerun the PowerShell installer from the install section:

irm https://raw.githubusercontent.com/RivoLink/leaf/main/scripts/install.ps1 | iex

macOS / Linux / Android / Termux:

Windows:

Remove-Item "$env:LOCALAPPDATA\Programs\leaf\leaf.exe" -Force

npm:

npm uninstall -g @rivolink/leaf
联系我们 contact @ memedata.com