diff --git a/deps/koino b/deps/koino index 060611d..bd71384 160000 --- a/deps/koino +++ b/deps/koino @@ -1 +1 @@ -Subproject commit 060611d230cea7996b4518a80137b3e96319a293 +Subproject commit bd71384edb665ee6cfecb573296c23ac6d15a033 diff --git a/src/main.zig b/src/main.zig index e637d1f..3d8514f 100644 --- a/src/main.zig +++ b/src/main.zig @@ -165,24 +165,6 @@ pub fn main() anyerror!void { } } -fn markdownToHtmlInternal(resultAllocator: *std.mem.Allocator, internalAllocator: *std.mem.Allocator, options: koino.Options, markdown: []const u8) ![]u8 { - var p = try koino.parser.Parser.init(internalAllocator, options); - try p.feed(markdown); - - var doc = try p.finish(); - p.deinit(); - - defer doc.deinit(); - - return try koino.html.print(resultAllocator, p.options, doc); -} - -pub fn markdownToHtml(allocator: *std.mem.Allocator, options: koino.Options, markdown: []const u8) ![]u8 { - var arena = std.heap.ArenaAllocator.init(allocator); - defer arena.deinit(); - return markdownToHtmlInternal(allocator, &arena.allocator, options, markdown); -} - const Date = struct { const Self = @This(); @@ -286,7 +268,12 @@ const Website = struct { } else null; if (heading_or_null) |heading| { - const string = try koino.html.print(&self.arena.allocator, markdown_options, heading); + var list = std.ArrayList(u8).init(&self.arena.allocator); + defer list.deinit(); + + try koino.html.print(list.writer(), &self.arena.allocator, markdown_options, heading); + + const string = list.toOwnedSlice(); std.debug.assert(std.mem.startsWith(u8, string, "

")); std.debug.assert(std.mem.endsWith(u8, string, "

\n")); @@ -441,7 +428,7 @@ const Website = struct { } /// Render a given markdown file into `dst_path`. - fn renderMarkdownFile(self: Self, src_path: []const u8, dst_dir: std.fs.Dir, dst_path: []const u8) !void { + fn renderMarkdownFile(self: *Self, src_path: []const u8, dst_dir: std.fs.Dir, dst_path: []const u8) !void { std.debug.assert(self.is_prepared); var markdown_input = try std.fs.cwd().readFileAlloc(self.allocator, src_path, 10_000_000); @@ -451,13 +438,25 @@ const Website = struct { } /// Render the given markdown source into `dst_path`. - fn renderMarkdown(self: Self, source: []const u8, dst_dir: std.fs.Dir, dst_path: []const u8) !void { + fn renderMarkdown(self: *Self, source: []const u8, dst_dir: std.fs.Dir, dst_path: []const u8) !void { std.debug.assert(self.is_prepared); - var rendered_markdown = try markdownToHtml(self.allocator, markdown_options, source); - defer self.allocator.free(rendered_markdown); + var p = try koino.parser.Parser.init(&self.arena.allocator, markdown_options); + try p.feed(source); + + var doc = try p.finish(); + p.deinit(); + + defer doc.deinit(); - try self.renderHtml(rendered_markdown, dst_dir, dst_path); + var output_file = try dst_dir.createFile(dst_path, .{}); + defer output_file.close(); + + var writer = output_file.writer(); + + try self.renderHeader(writer); + try koino.html.print(writer, &self.arena.allocator, p.options, doc); + try self.renderFooter(writer); } /// Render the markdown body into `dst_path`. @@ -609,4 +608,13 @@ const Website = struct { ); } } + + fn renderArticle(self: *Website, article: Article, dst_dir: std.fs.Dir, dst_name: []const u8) !void { + var formatter = HtmlFormatter.init(allocator, options); + defer formatter.deinit(); + + try formatter.format(root, false); + + return formatter.buffer.toOwnedSlice(); + } }; diff --git a/website/tutorials/02-embedded-programming.md b/website/tutorials/02-embedded-programming.md index 9b6b7e9..5362598 100644 --- a/website/tutorials/02-embedded-programming.md +++ b/website/tutorials/02-embedded-programming.md @@ -4,6 +4,8 @@ In this tutorial, you'll learn the ways of the embedded programmer and how to ma ## Prerequisites + + - [Embedded Basics](01-embedded-basics.htm) ## Contents @@ -48,7 +50,7 @@ So to get an embedded program up and running, we first need to check out the *me ![Memory Map of LPC1768](../img/memory-map.png) -Here you can see that the memory contains continuous flash memory (*On-chip non-volatile memory*), two sections of SRAM (*On-chip SRAM*), some *Boot ROM*, and peripherials. +Here you can see that the memory contains continuous flash memory (*On-chip [non-volatile memory](https://en.wikipedia.org/wiki/Non-volatile_memory)*), two sections of SRAM (*On-chip [SRAM](https://en.wikipedia.org/wiki/Static_random-access_memory)*), some *Boot ROM*, and peripherials. This memory map tells us how to design the [linker script](https://ftp.gnu.org/old-gnu/Manuals/ld-2.9.1/html_chapter/ld_3.html#SEC6) and how to lay out our sections (`.text`, `.data`, …). As sections are quite complex topic for themselves, they [will be explained later](#text-data-and-other-curious-sections). For now, we only need to know that `.text` is all of our code (this is where our functions live), `.rodata` is pre-initialized immutable data, `.data` is the pre-initialized mutable data and `.bss` is zero-initialized mutable data.