Skip to content

Commit 9a28762

Browse files
committed
Define render_code and render_link in markdown impl
1 parent a6c136b commit 9a28762

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

sample_programs/build_site.gdn

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,49 @@ fun render_inline(src: String): String {
3030
"".join(parts)
3131
}
3232

33+
// Render the next backtick text as code, and return the remainder of
34+
// the text to process.
35+
fun render_backtick(src: String): (String, String) {
36+
assert(src.starts_with("`"))
37+
src = src.substring(1, src.len())
38+
39+
match src.split_once("`") {
40+
Some(parts) => {
41+
let (before, after) = parts
42+
("".join(["<code>", before, "</code>"]), after)
43+
}
44+
None => {
45+
("", src)
46+
}
47+
}
48+
}
49+
50+
fun render_link(src: String): (String, String) {
51+
assert(src.starts_with("["))
52+
src = src.substring(1, src.len())
53+
54+
src.split_once("](")
55+
match src.split_once("](") {
56+
Some(parts) => {
57+
let (url_text, after_paren) = parts
58+
match after_paren.split_once(")") {
59+
Some(parts) => {
60+
let (url, after) = parts
61+
("".join(["<a href=\"", url, "\">", url_text, "</a>"]), after)
62+
}
63+
None => (src, "")
64+
}
65+
}
66+
None => {
67+
("", src)
68+
}
69+
}
70+
}
71+
72+
{
73+
render_link("[click me](example.com) b")
74+
}
75+
3376
fun render_markdown_paragraph(src: String): String {
3477
"".join(["<p>", render_inline(src), "</p>"])
3578
}

0 commit comments

Comments
 (0)