const std = @import("std");

pub fn parse(src: []const u8, alloc: std.mem.Allocator) ![][]const u8 {
    var it = std.mem.splitScalar(u8, src, '\n');

    var lines = std.ArrayList([]const u8).init(alloc);

    while (it.next()) |line| {
        try lines.append(line);
    }

    return try lines.toOwnedSlice();
}

// pub fn render(src: []const u8, alloc: std.mem.Allocator) ![]const u8 {
//     // std.mem.tokenizeScalar(comptime T: type, buffer: []const T, delimiter: T)
// }

test "split-lines" {
    const alloc = std.testing.allocator;

    const src =
        \\hello world!
        \\
        \\this is some content!
        \\
    ;

    const lines = try parse(src, alloc);
    defer alloc.free(lines);

    const expect: []const []const u8 = &.{
        "hello world!",
        "",
        "this is some content!",
        "",
    };

    try std.testing.expectEqualDeep(
        expect,
        lines,
    );
}

test "2.2 Tabs" {
    // const alloc = std.testing.allocator;
    //
    // const md = "\tfoo\tbaz\t\tbim";

    // const expect = "<pre><code>foo\tbaz\t\tbim</code></pre>";
    // const actual = try render(md, alloc);
    // defer alloc.free(actual);
    // std.testing.expectEqualStrings(expect, actual);
}
