# CLAUDE.md
Always answer my question in Simplified Chinese.
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
## Project Overview
This project is a command-line tool written in Rust for formatting markdown files. It can add spacing, handle empty lines, align tables, and format lists. The main application logic is contained within `src/main.rs` .
## Common Commands
- **Build the project:**
```bash
cargo build
```
- **Build for release:**
```bash
cargo build --release
```
- **Run tests:**
```bash
cargo test
```
- **Run a specific test:**
```bash
cargo test test_name
```
- **Run tests in the tests/ directory (integration tests):**
```bash
cargo test --test cli
```
- **Run tests in main.rs (unit tests):**
```bash
cargo test --lib
```
- **Run the formatter on a file:**
```bash
cargo run -- input.md -o output.md
```
- **Run formatter with stdin/stdout:**
```bash
cat input.md | cargo run > output.md
```
- **Cross-platform release builds (using .build.sh):**
```bash
bash .build.sh
```
This builds for Windows (x86_64-pc-windows-gnu) and Linux (x86_64-unknown-linux-musl) targets and creates distribution archives.
## Architecture
The application is structured as a single-file Rust program in `src/main.rs` .
- ** `main` function**: Handles command-line argument parsing using `clap` , reads the input file (or stdin), calls the formatting logic, and writes to the output file (or stdout).
- ** `format_markdown` function**: The main formatting entry point. It orchestrates the various formatting passes.
- **State Machine**: A simple state machine ( `LineState` enum) is used to process the markdown file line-by-line in `format_lines` . This handles context-aware formatting rules, like adding blank lines before/after code blocks, tables, and headers.
- **Formatting Functions**:
- `format_lines` : Applies basic formatting rules based on the `LineState` .
- `format_lists` : Normalizes and re-numbers ordered and unordered lists, including nested lists.
- `format_text` : Adds spaces between CJK and ASCII characters and around inline code spans using regex.
- `format_tables` : Uses the `markdown-table-formatter` crate to align tables.
- **Testing**: Inline test module ( `#[cfg(test)] mod tests` ) contains unit tests for various formatting scenarios.