Updates koino.

wch-ch32v003
Felix (xq) Queißner 4 years ago
parent 0bf65bef97
commit f159621701

2
deps/koino vendored

@ -1 +1 @@
Subproject commit 060611d230cea7996b4518a80137b3e96319a293 Subproject commit bd71384edb665ee6cfecb573296c23ac6d15a033

@ -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 Date = struct {
const Self = @This(); const Self = @This();
@ -286,7 +268,12 @@ const Website = struct {
} else null; } else null;
if (heading_or_null) |heading| { 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, "<h1>")); std.debug.assert(std.mem.startsWith(u8, string, "<h1>"));
std.debug.assert(std.mem.endsWith(u8, string, "</h1>\n")); std.debug.assert(std.mem.endsWith(u8, string, "</h1>\n"));
@ -441,7 +428,7 @@ const Website = struct {
} }
/// Render a given markdown file into `dst_path`. /// 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); std.debug.assert(self.is_prepared);
var markdown_input = try std.fs.cwd().readFileAlloc(self.allocator, src_path, 10_000_000); 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`. /// 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); std.debug.assert(self.is_prepared);
var rendered_markdown = try markdownToHtml(self.allocator, markdown_options, source); var p = try koino.parser.Parser.init(&self.arena.allocator, markdown_options);
defer self.allocator.free(rendered_markdown); 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`. /// 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();
}
}; };

@ -4,6 +4,8 @@ In this tutorial, you'll learn the ways of the embedded programmer and how to ma
## Prerequisites ## Prerequisites
<!-- FOO -->
- [Embedded Basics](01-embedded-basics.htm) - [Embedded Basics](01-embedded-basics.htm)
## Contents ## 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) ![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. 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.

Loading…
Cancel
Save