From 8690d2a8575a9d3561d32417ab85df3759504bed Mon Sep 17 00:00:00 2001 From: ruohki Date: Sat, 28 Feb 2026 22:18:31 +0100 Subject: [PATCH] feat(02-02): add code block borders with syntax highlighting and GFM table grid MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - emit_code_block: ╭─ {lang} ─╮ / │ content │ / ╰──╯ rounded borders; lang label in Yellow; content via highlight_code() - emit_table: ┌┬┐├┼┤└┴┘ full box-drawing grid; bold LightCyan header row; Left/Right/Center cell alignment - Rename stub methods to emit_code_block_now / emit_table_now (clean naming; delegates to full emitters) - Remove unused push_fg / push_fg_mod helper methods - cargo check passes; 19 expected dead_code warnings (modules wired in Plan 03) --- src/renderer.rs | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/src/renderer.rs b/src/renderer.rs index 8f9773f..716f350 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -92,18 +92,6 @@ impl RenderState { self.style_stack.push(new_style); } - /// Push a completely new foreground-colored style. - fn push_fg(&mut self, color: Color) { - let new_style = Style::default().fg(color); - self.style_stack.push(new_style); - } - - /// Push a new style with a foreground color and modifier. - fn push_fg_mod(&mut self, color: Color, modifier: Modifier) { - let new_style = Style::default().fg(color).add_modifier(modifier); - self.style_stack.push(new_style); - } - // ── Line flushing ───────────────────────────────────────────────────────── /// Flush `current_spans` into a `Line`, optionally prepending blockquote borders. @@ -184,20 +172,22 @@ impl RenderState { self.push_blank(); } - // ── Code block stub ─────────────────────────────────────────────────────── - // (will be replaced in Task 2 with full border + highlighting) + // ── Code block emitter ──────────────────────────────────────────────────── - fn emit_code_block_stub(&mut self) { + /// Flush the accumulated code buffer and emit a bordered, syntax-highlighted + /// code block into `self.lines`. + fn emit_code_block_now(&mut self) { let code = std::mem::take(&mut self.code_buf); let lang = std::mem::take(&mut self.code_lang); let width = self.width; emit_code_block(&code, &lang, width, &mut self.lines); } - // ── Table stub ──────────────────────────────────────────────────────────── - // (will be replaced in Task 2 with full box-drawing grid) + // ── Table emitter ───────────────────────────────────────────────────────── - fn emit_table_stub(&mut self) { + /// Flush the accumulated table rows and emit a full box-drawing grid table + /// into `self.lines`. + fn emit_table_now(&mut self) { let alignments = std::mem::take(&mut self.table_alignments); let rows = std::mem::take(&mut self.table_rows); emit_table(&alignments, &rows, &mut self.lines); @@ -284,7 +274,7 @@ fn handle_event(state: &mut RenderState, event: Event) { } Event::End(TagEnd::CodeBlock) => { state.in_code_block = false; - state.emit_code_block_stub(); + state.emit_code_block_now(); } // ── Lists ───────────────────────────────────────────────────────────── @@ -388,7 +378,7 @@ fn handle_event(state: &mut RenderState, event: Event) { } Event::End(TagEnd::Table) => { state.in_table = false; - state.emit_table_stub(); + state.emit_table_now(); } Event::Start(Tag::TableHead) => { state.in_table_head = true;