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*.
Beid::Editing.set_attribute(document, 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.

Syntax and metadata

Inspect headings, links, tables, task lists, and footnotes. Retain front matter and HTML-comment directives without evaluating their contents.

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

Each edit returns a new document. Find its nodes again before your next edit. Continue with Getting started.

Work with the source.

Start with one edit, then explore the API and its limits.