diff options
author | Akshay <[email protected]> | 2024-07-14 13:01:23 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2024-07-14 13:01:23 +0100 |
commit | 9ad06d721c1e481c82b4f43df819d76e35757282 (patch) | |
tree | debfca71dcdaeac93ac12abedd377f66cf4341fc /examples/md-to-html | |
parent | 83b537bb860643ebdabc43ab47cb8645da8a2e6d (diff) |
add examples
Diffstat (limited to 'examples/md-to-html')
-rw-r--r-- | examples/md-to-html/convert.tbsp | 65 | ||||
-rw-r--r-- | examples/md-to-html/doc.md | 21 | ||||
-rw-r--r-- | examples/md-to-html/out.html | 20 | ||||
-rw-r--r-- | examples/md-to-html/readme.txt | 3 |
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 @@ | |||
1 | BEGIN { | ||
2 | int depth = 0; | ||
3 | |||
4 | print("<html>\n"); | ||
5 | print("<body>\n"); | ||
6 | } | ||
7 | |||
8 | enter section { | ||
9 | depth += 1; | ||
10 | } | ||
11 | leave section { | ||
12 | depth -= 1; | ||
13 | } | ||
14 | |||
15 | enter atx_heading { | ||
16 | print("<h"); | ||
17 | print(depth); | ||
18 | print(">"); | ||
19 | } | ||
20 | leave atx_heading { | ||
21 | print("</h"); | ||
22 | print(depth); | ||
23 | print(">\n"); | ||
24 | } | ||
25 | |||
26 | enter paragraph { | ||
27 | print("<p>"); | ||
28 | } | ||
29 | leave paragraph { | ||
30 | print("</p>\n"); | ||
31 | } | ||
32 | |||
33 | enter list { | ||
34 | print("<ol>"); | ||
35 | } | ||
36 | leave list { | ||
37 | print("</ol>\n"); | ||
38 | } | ||
39 | |||
40 | enter list_item { | ||
41 | print("<li>"); | ||
42 | } | ||
43 | leave list_item { | ||
44 | print("</li>\n"); | ||
45 | } | ||
46 | |||
47 | enter fenced_code_block { | ||
48 | print("<pre>"); | ||
49 | } | ||
50 | leave fenced_code_block { | ||
51 | print("</pre>\n"); | ||
52 | } | ||
53 | |||
54 | enter inline { | ||
55 | print(text(node)); | ||
56 | } | ||
57 | enter code_fence_content { | ||
58 | print(text(node)); | ||
59 | } | ||
60 | |||
61 | END { | ||
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 | |||
3 | content of first paragraph | ||
4 | |||
5 | ## 1.1 heading | ||
6 | |||
7 | content of nested paragraph | ||
8 | |||
9 | # 2 heading | ||
10 | |||
11 | content of second paragraph | ||
12 | |||
13 | ``` | ||
14 | // some code in the code block | ||
15 | fn 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 | ||
10 | fn 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 @@ | |||
1 | proof-of-concept markdown-to-html converter using tbsp: | ||
2 | |||
3 | tbsp -f convert.tbsp -l md < doc.md > out.html | ||