From 9e6f79c2337e1fb035382462e1d66ac4413c2fd2 Mon Sep 17 00:00:00 2001 From: ruohki Date: Sat, 28 Feb 2026 22:17:28 +0100 Subject: [PATCH] feat(02-02): build core markdown renderer with inline and block elements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Create src/renderer.rs with public render_markdown(input, width) -> Vec> - Implement RenderState with style stack, blockquote depth, list counters, table two-pass collection - Handle all inline elements: headings H1-H6 (CGA colors + H1/H2 decorators), bold, italic, inline code - Handle block elements: paragraphs, lists (ordered/unordered/nested with •/◦/▪), blockquotes with │ prefix, horizontal rules, images as [IMAGE: alt] placeholders - Stub emit_code_block and emit_table delegate to full implementations (Task 2) - Add mod highlighter, renderer, vault declarations to main.rs (wiring for Plan 03) - cargo check passes clean (19 dead_code warnings expected — modules unwired until Plan 03) --- src/main.rs | 3 + src/renderer.rs | 713 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 716 insertions(+) create mode 100644 src/renderer.rs diff --git a/src/main.rs b/src/main.rs index e92043d..ac6a5fc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,10 @@ mod app; mod config; +mod highlighter; +mod renderer; mod signals; mod terminal; +mod vault; fn main() { // ── PRE-TERMINAL PHASE ──────────────────────────────────────────────────── diff --git a/src/renderer.rs b/src/renderer.rs new file mode 100644 index 0000000..8f9773f --- /dev/null +++ b/src/renderer.rs @@ -0,0 +1,713 @@ +//! Markdown-to-styled-lines renderer for bbs-md. +//! +//! Converts a markdown string into `Vec>` using pulldown-cmark +//! event processing, CGA-themed styling, syntax-highlighted code blocks, and +//! box-drawing table grids. +//! +//! # Public API +//! +//! - `render_markdown(input: &str, width: u16) -> Vec>` + +use pulldown_cmark::{ + Alignment, CodeBlockKind, Event, HeadingLevel, Options, Parser, Tag, TagEnd, TextMergeStream, +}; +use ratatui::style::{Color, Modifier, Style}; +use ratatui::text::{Line, Span}; + +// ── RenderState ─────────────────────────────────────────────────────────────── + +/// Internal mutable state threaded through the event handler. +struct RenderState { + /// Accumulated output lines. + lines: Vec>, + /// Spans for the current (in-progress) line. + current_spans: Vec>, + /// Style stack — push on block/inline Start, pop on End. + style_stack: Vec