From 9ad06d721c1e481c82b4f43df819d76e35757282 Mon Sep 17 00:00:00 2001 From: Akshay Date: Sun, 14 Jul 2024 13:01:23 +0100 Subject: add examples --- examples/md-to-html/convert.tbsp | 65 ++++++++++++++++++++++++++++++++++++++++ examples/md-to-html/doc.md | 21 +++++++++++++ examples/md-to-html/out.html | 20 +++++++++++++ examples/md-to-html/readme.txt | 3 ++ 4 files changed, 109 insertions(+) create mode 100644 examples/md-to-html/convert.tbsp create mode 100644 examples/md-to-html/doc.md create mode 100644 examples/md-to-html/out.html create mode 100644 examples/md-to-html/readme.txt (limited to 'examples/md-to-html') 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 @@ +BEGIN { + int depth = 0; + + print("\n"); + print("\n"); +} + +enter section { + depth += 1; +} +leave section { + depth -= 1; +} + +enter atx_heading { + print(""); +} +leave atx_heading { + print("\n"); +} + +enter paragraph { + print("

"); +} +leave paragraph { + print("

\n"); +} + +enter list { + print("
    "); +} +leave list { + print("
\n"); +} + +enter list_item { + print("
  • "); +} +leave list_item { + print("
  • \n"); +} + +enter fenced_code_block { + print("
    ");
    +}
    +leave fenced_code_block {
    +    print("
    \n"); +} + +enter inline { + print(text(node)); +} +enter code_fence_content { + print(text(node)); +} + +END { + print("\n"); + print("\n"); +} + 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 heading + +content of first paragraph + +## 1.1 heading + +content of nested paragraph + +# 2 heading + +content of second paragraph + +``` +// some code in the code block +fn main() { } +``` + +- who dosent +- despise +- lists + 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 heading

    +

    content of first paragraph

    +

    1.1 heading

    +

    content of nested paragraph

    +

    2 heading

    +

    content of second paragraph

    +
    // some code in the code block
    +fn main() { }
    +
    +
    1. who dosent

      +
    2. +
    3. despise

      +
    4. +
    5. lists

      +
    6. +
    + + 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 @@ +proof-of-concept markdown-to-html converter using tbsp: + + tbsp -f convert.tbsp -l md < doc.md > out.html -- cgit v1.2.3