markdown-live-preview 0.1.0

A live Markdown preview server with WebSocket and HTML rendering
Documentation
# ๐Ÿฆ€ 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

| Feature              | Status | Notes |
|----------------------|--------|-------|
| 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:

| Event         | Payload Structure                                |
|----------------|--------------------------------------------------|
| 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/