Skip to content
Ilia Maslakov edited this page Oct 18, 2026 · 1 revision

One file, many languages

Markdown hands each fenced block to the rules of the language it names, and those rules hand on what they embed in turn.

Shell, with awk, Python and SQL inside

#!/bin/sh
# count the expressions of a log, then store the total
total=$(awk '/^= / { n++ } END { print n }' "${LOG:-calc.log}")
python3 - <<EOF
import json
print(json.dumps({"total": $total}))
EOF
sqlite3 stats.db <<EOF
INSERT INTO runs (total, day) VALUES ($total, date('now'));
SELECT count(*) FROM runs WHERE total > 10;
EOF

HTML, with CSS and JavaScript inside

<style>
  .result { color: #2a7; font-weight: bold; }
</style>
<input id="expr" value="2 3 +">
<script>
  const out = document.querySelector(".result");
  out.textContent = `= ${eval("2 + 3")}`;
</script>

A Jinja2 template

{# the report of one run #}
<h1>{{ suite | upper }}</h1>
{% for case in cases if case.ok %}
  <li>{{ case.input }} = {{ case.result | round(2) }}</li>
{% endfor %}

C and JSON

static int
apply (token_kind_t kind, rpn_stack_t *s)
{
    if (stack_pop (s, &b) != 0)   /* nothing to pop */
        return -1;
    return stack_push (s, a / b);
}
{ "input": "6 7 *", "expect": 42, "tags": ["mul"], "slow": false }

A diagram

sequenceDiagram
    participant U as User
    participant C as calc
    U->>C: 2 3 +
    C-->>U: = 5
    Note over C: the stack is empty again
Loading

A diff

--- a/calc.c
+++ b/calc.c
@@ -10,3 +10,3 @@
     if (b == 0.0)
-        return 0.0;
+        return b < 0.0 ? -1.0 : 1.0;

Clone this wiki locally