diff options
| -rw-r--r-- | issues.md | 4 | ||||
| -rw-r--r-- | src/markdown.zig | 33 |
2 files changed, 34 insertions, 3 deletions
@@ -1,6 +1,6 @@ - [x] at the end of _any_ **kind** ~of~ `formatting`, ALL styles are cleared, which for user-text clears the background that should still be there. - [x] screen flickers. I think our differential rendering has gotten broken and we're re-drawing the full conversation on every update. - [x] tool components don't have their collapsed form any more, they're always showing their output expanded, ctrl+o does nothing. -- [ ] empty lines in user-text are getting dropped - (shift+enter)*2 doesn't show an empty line in the middle when the user text is rendered in the component. - - [ ] in another test, this text: "`code block`\n_underline_\n**bold**\n~strikethrough~" was collapsed down to one line with just spaces between them. this time it wasn't even a double-newline. +- [x] empty lines in user-text are getting dropped - (shift+enter)*2 doesn't show an empty line in the middle when the user text is rendered in the component. + - [x] in another test, this text: "`code block`\n_underline_\n**bold**\n~strikethrough~" was collapsed down to one line with just spaces between them. this time it wasn't even a double-newline. - [ ] keybindings need to work while the agent is working in a loop. most important: Escape should interrupt the agent wherever it is, return back to user-input mode (to avoid a broken convo history we'll have to clear any tool calls that didn't get results). diff --git a/src/markdown.zig b/src/markdown.zig index fad1676..58f1b97 100644 --- a/src/markdown.zig +++ b/src/markdown.zig @@ -286,6 +286,7 @@ pub const Renderer = struct { }, c.MD_BLOCK_P => { self.flushParagraph() catch |e| return self.fail(e); + if (self.list_item_depth == 0) self.appendBlank() catch |e| return self.fail(e); }, c.MD_BLOCK_LI => { self.flushParagraph() catch |e| return self.fail(e); @@ -337,7 +338,7 @@ pub const Renderer = struct { const self: *Renderer = @ptrCast(@alignCast(userdata.?)); const s = p[0..@intCast(size)]; switch (t) { - c.MD_TEXT_BR, c.MD_TEXT_SOFTBR => self.add(" ") catch |e| return self.fail(e), + c.MD_TEXT_BR, c.MD_TEXT_SOFTBR => self.add("\n") catch |e| return self.fail(e), c.MD_TEXT_NULLCHAR => self.add("�") catch |e| return self.fail(e), c.MD_TEXT_ENTITY => self.add(decodeEntity(s)) catch |e| return self.fail(e), else => self.add(s) catch |e| return self.fail(e), @@ -386,6 +387,36 @@ test "Renderer uses MD4C for common markdown" { try testing.expect(found_code); } +test "Renderer preserves user-authored line breaks and blank paragraph lines" { + var out: std.ArrayList([]const u8) = .empty; + defer { + for (out.items) |l| testing.allocator.free(l); + out.deinit(testing.allocator); + } + var r: Renderer = .{ .alloc = testing.allocator, .width = 80, .out_lines = &out }; + try r.render("first\nsecond\n\nthird"); + try testing.expectEqual(@as(usize, 4), out.items.len); + try testing.expectEqualStrings("first", out.items[0]); + try testing.expectEqualStrings("second", out.items[1]); + try testing.expectEqualStrings("", out.items[2]); + try testing.expectEqualStrings("third", out.items[3]); +} + +test "Renderer keeps soft breaks between inline-styled lines" { + var out: std.ArrayList([]const u8) = .empty; + defer { + for (out.items) |l| testing.allocator.free(l); + out.deinit(testing.allocator); + } + var r: Renderer = .{ .alloc = testing.allocator, .width = 80, .out_lines = &out }; + try r.render("`code block`\n_underline_\n**bold**\n~strikethrough~"); + try testing.expectEqual(@as(usize, 4), out.items.len); + try testing.expect(std.mem.indexOf(u8, out.items[0], "code block") != null); + try testing.expect(std.mem.indexOf(u8, out.items[1], "underline") != null); + try testing.expect(std.mem.indexOf(u8, out.items[2], "bold") != null); + try testing.expect(std.mem.indexOf(u8, out.items[3], "strikethrough") != null); +} + test "Renderer preserves nested list indentation" { var out: std.ArrayList([]const u8) = .empty; defer { |
