Markdown editing for Ruby

Edit Markdown without rewriting it.

Beid changes the exact source range you choose. Everything else—spacing, syntax, and structure—stays as the author wrote it.

A heading edit leaves the rest of the source intact
Original source
# Title

Keep this *formatting*.
set_attribute(heading, :level, 2)
Edited source
## Title

Keep this *formatting*.

Changes that respect the file.

Use the parse tree for targeted edits, while the original Markdown remains the source of truth.

Exact round trips

Read source-positioned nodes and return the original bytes with Document#to_s. Untouched formatting is never regenerated.

Precise positions

Work with half-open byte ranges, Unicode columns, and LSP UTF-16 positions for editor integrations.

Immutable edits

Replace, insert, remove, or move content. Each operation returns a new document, leaving the original unchanged.

Make one change. Keep the rest.

Beid requires Ruby 3.1 or newer and has no runtime dependencies beyond the standard library.

Install
gem install beid
Edit a heading
require "beid"

source = "# Title\n\nKeep this *formatting*.\n"
document = Beid::Document.parse(source)
heading = document.root.children.first

updated = Beid::Editing.set_attribute(document, heading, :level, 2)
puts updated.to_s

Beid is an editing view, not an HTML renderer. Read the editing API and limits.