markdown-live-preview

Crates.iomarkdown-live-preview
lib.rsmarkdown-live-preview
version0.1.0
created_at2025-06-18 02:02:30.996962+00
updated_at2025-06-18 02:02:30.996962+00
descriptionA live Markdown preview server with WebSocket and HTML rendering
homepage
repositoryhttps://github.com/popplestones/markdown-live-preview
max_upload_size
id1716458
size99,599
Shane Poppleton (codemonkey76)

documentation

README

๐Ÿฆ€ markdown-live-preview

A Rust-powered live Markdown preview server that integrates with Neovim via TCP.
Renders GitHub-flavored Markdown (GFM) using Comrak, served via Axum, and controlled in real time from an 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

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

{
  "event": "init",
  "data": {
    "content": ["# Hello", "world!"],
    "cursor": [1, 0]
  }
}

Supported event types:

Event Payload Structure
init { content: Vec, 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
  • Automatically opens in the default browser on launch
  • Reflects live updates from Neovim

๐Ÿ›  Architecture

[ Neovim (plugin) ] --> TCP (127.0.0.1:3001) --> [ markdown-live-preview ]
                                              --> Axum --> HTML preview (localhost:3000)

๐Ÿงช Debugging

You can log incoming messages using:

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

Commit count: 5

cargo fmt