# ๐ฆ markdown-live-preview
A Rust-powered live Markdown preview server that integrates with Neovim via TCP.
Renders GitHub-flavored Markdown (GFM) using [Comrak](https://github.com/kivikakk/comrak), served via [Axum](https://github.com/tokio-rs/axum), and controlled in real time from an [md-live-preview.nvim](https://github.com/popplestones/md-live-preview.nvim) plugin.
> [!NOTE]
> This project is designed to be paired with a Neovim plugin that streams buffer changes and cursor position.
---
## ๐ฆ Features
| Live buffer preview | โ
| Renders latest Markdown buffer to HTML |
| Cursor tracking | โ
| Receives cursor position updates |
| Incremental updates | โ
| Only sends changed lines |
| GFM rendering | โ
| Uses `comrak` with alerts, tables, etc. |
| Local TCP interface | โ
| Neovim pushes updates to `127.0.0.1:3001` |
| HTML server | โ
| Axum serves preview on `http://localhost:3000` |
| Auto-launch browser | โ
| Opens system browser on start |
| WebSocket live reload | ๐ง | Planned |
---
## ๐ Getting Started
### ๐ง Prerequisites
- Rust (1.70+ recommended)
- Neovim 0.9+
- `md-live-preview.nvim` installed and configured
### ๐ Build and run
```bash
git clone https://github.com/popplestones/markdown-live-preview
cd markdown-live-preview
cargo build --release
./target/release/markdown-live-preview
```
### ๐ Communication Protocol
The server listens on `127.0.0.1:3001` for newline-delimited JSON messages.
#### โ๏ธ Incoming message format
```json
{
"event": "init",
"data": {
"content": ["# Hello", "world!"],
"cursor": [1, 0]
}
}
```
Supported `event` types:
| init | { content: Vec<String>, cursor: (usize, usize) } |
| buffer_change | { line: usize, new_text: String } |
| cursor_moved | { cursor: (usize, usize) } |
> [!TIP]
> Lines are indexed from zero.
## ๐ Web Interface
- URL: [http://localhost:3000](http://localhost:3000)
- Automatically opens in the default browser on launch
- Reflects live updates from Neovim
## ๐ Architecture
```text
[ Neovim (plugin) ] --> TCP (127.0.0.1:3001) --> [ markdown-live-preview ]
--> Axum --> HTML preview (localhost:3000)
```
## ๐งช Debugging
You can log incoming messages using:
```bash
RUST_LOG=debug ./target/release/markdown-live-preview
```
> [!WARNING]
> Always restart the server if you change port bindings or encounter connection issues.
## ๐ License
MIT ยฉ Shane Poppleton
## ๐ Acknowledgments
- [Comrak](https://github.com/kivikakk/comrak)
- [Axum](https://github.com/tokio-rs/axum)
- [Lua TCP with vim.loop](https://neovim.io/)