aboutsummaryrefslogtreecommitdiff
path: root/examples/md-to-html
diff options
context:
space:
mode:
Diffstat (limited to 'examples/md-to-html')
-rw-r--r--examples/md-to-html/convert.tbsp65
-rw-r--r--examples/md-to-html/doc.md21
-rw-r--r--examples/md-to-html/out.html20
-rw-r--r--examples/md-to-html/readme.txt3
4 files changed, 109 insertions, 0 deletions
diff --git a/examples/md-to-html/convert.tbsp b/examples/md-to-html/convert.tbsp
new file mode 100644
index 0000000..103bcaa
--- /dev/null
+++ b/examples/md-to-html/convert.tbsp
@@ -0,0 +1,65 @@
1BEGIN {
2 int depth = 0;
3
4 print("<html>\n");
5 print("<body>\n");
6}
7
8enter section {
9 depth += 1;
10}
11leave section {
12 depth -= 1;
13}
14
15enter atx_heading {
16 print("<h");
17 print(depth);
18 print(">");
19}
20leave atx_heading {
21 print("</h");
22 print(depth);
23 print(">\n");
24}
25
26enter paragraph {
27 print("<p>");
28}
29leave paragraph {
30 print("</p>\n");
31}
32
33enter list {
34 print("<ol>");
35}
36leave list {
37 print("</ol>\n");
38}
39
40enter list_item {
41 print("<li>");
42}
43leave list_item {
44 print("</li>\n");
45}
46
47enter fenced_code_block {
48 print("<pre>");
49}
50leave fenced_code_block {
51 print("</pre>\n");
52}
53
54enter inline {
55 print(text(node));
56}
57enter code_fence_content {
58 print(text(node));
59}
60
61END {
62 print("</body>\n");
63 print("</html>\n");
64}
65
diff --git a/examples/md-to-html/doc.md b/examples/md-to-html/doc.md
new file mode 100644
index 0000000..2a38bb0
--- /dev/null
+++ b/examples/md-to-html/doc.md
@@ -0,0 +1,21 @@
1# 1 heading
2
3content of first paragraph
4
5## 1.1 heading
6
7content of nested paragraph
8
9# 2 heading
10
11content of second paragraph
12
13```
14// some code in the code block
15fn main() { }
16```
17
18- who dosent
19- despise
20- lists
21
diff --git a/examples/md-to-html/out.html b/examples/md-to-html/out.html
new file mode 100644
index 0000000..9b03976
--- /dev/null
+++ b/examples/md-to-html/out.html
@@ -0,0 +1,20 @@
1<html>
2<body>
3<h1>1 heading</h1>
4<p>content of first paragraph</p>
5<h2>1.1 heading</h2>
6<p>content of nested paragraph</p>
7<h1>2 heading</h1>
8<p>content of second paragraph</p>
9<pre>// some code in the code block
10fn main() { }
11</pre>
12<ol><li><p>who dosent</p>
13</li>
14<li><p>despise</p>
15</li>
16<li><p>lists</p>
17</li>
18</ol>
19</body>
20</html>
diff --git a/examples/md-to-html/readme.txt b/examples/md-to-html/readme.txt
new file mode 100644
index 0000000..812c1e6
--- /dev/null
+++ b/examples/md-to-html/readme.txt
@@ -0,0 +1,3 @@
1proof-of-concept markdown-to-html converter using tbsp:
2
3 tbsp -f convert.tbsp -l md < doc.md > out.html