mymarkdown

My markdown
git clone https://git.grace.moe/mymarkdown
Log | Files | Refs

commit 2b57651ee184c93a9c69d5d4a680115fd637ee34
parent 154e25f7cbe0917a28087b5a5061e4d35dcefa7b
Author: gracefu <81774659+gracefuu@users.noreply.github.com>
Date:   Wed, 21 May 2025 02:56:47 +0800

Fix bug in paragraph interrupt logic + don't out of bounds in thematic break parser

Diffstat:
Msrc/AstGen3.zig | 16+++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/AstGen3.zig b/src/AstGen3.zig @@ -353,8 +353,7 @@ inline fn parseColumnImpl( '*' => { if (std.mem.eql(u8, line.toUnpaddedSlice()[0..3], "***")) { const after_stars = line.sliceOpen(3); - const skip_whitespace_idx = after_stars.indexOfNone(" \t"); - if (after_stars.index(skip_whitespace_idx) == '\n') { + if (after_stars.len == after_stars.indexOfNotSpaceOrTab()) { self.scanner.advance(); tracy_frame.setName(@tagName(.thematic_break)); break :block_idx try self.appendLeafNode(parent_idx, .thematic_break, line.ptr, 3); @@ -374,11 +373,18 @@ inline fn parseColumnImpl( while (self.scanner.peek()) |peek2| { _, const line2 = peek2; + // Empty line (only spaces / tabs) if (line2.len == 0) break; - if (line2.index(line2.indexOfNotSpaceOrTab()) == '\n') break; - if (str.isAnyOf(line2.index(0), "-.:+>#")) break; - if (line2.len >= 3 and std.mem.allEqual(u8, line2.toUnpaddedSlice()[0..3], '*') and line2.index(line2.indexOfNotSpaceOrTab()) == '\n') break; + if (line2.len == line2.indexOfNotSpaceOrTab()) break; + // Special block chars + if (str.isAnyOf(line2.index(0), "-.:+>#@")) break; + // Thematic break + if (line2.len >= 3 and + std.mem.allEqual(u8, line2.toUnpaddedSlice()[0..3], '*') and + line2.len == 3 + line2.sliceOpen(3).indexOfNotSpaceOrTab()) break; + // Verbatim block if (line2.len >= 2 and std.mem.eql(u8, line2.toUnpaddedSlice()[0..2], "==")) break; + // Math block if (line2.len >= 3 and std.mem.eql(u8, line2.toUnpaddedSlice()[0..3], "$==")) break; try self.insertTextLine(.space_text, .text, paragraph_idx, line2); self.scanner.advance();