diff options
author | Ekaitz Zarraga <ekaitz@elenq.tech> | 2025-08-19 22:38:50 +0200 |
---|---|---|
committer | Ekaitz Zarraga <ekaitz@elenq.tech> | 2025-08-19 22:40:48 +0200 |
commit | 121b1328324b5eb77a19c1d2f6080482bd4e07fa (patch) | |
tree | d7eb0991f3eaa35dbcc4eda46006c379ced5b787 | |
parent | 252a4f525210d1b5a0dca71c337695a117c06156 (diff) |
html: WIP: Add html output command
-rw-r--r-- | cook/cli.scm | 9 | ||||
-rw-r--r-- | cook/html.scm | 35 | ||||
-rw-r--r-- | cook/html.sld | 8 |
3 files changed, 51 insertions, 1 deletions
diff --git a/cook/cli.scm b/cook/cli.scm index 1b5db87..f912a89 100644 --- a/cook/cli.scm +++ b/cook/cli.scm @@ -1,5 +1,6 @@ (import (cook parse-internals) (cook debug) + (cook html) (chibi) (chibi app) (chibi config) @@ -15,6 +16,11 @@ (let ((recipe (parse-cook (file->string recipe-file)))) (display (cook->list recipe)))) +(define (html-cook cfg spec recipe-file) + (let ((recipe (parse-cook (file->string recipe-file)))) + (display (recipe->html recipe)) + (newline))) + (run-application `(cook "Cooklang recipe tool" @@ -22,6 +28,7 @@ (help boolean (#\h ) "show this help")) (or (help "Show this help" () (,app-help-command)) - (read "Read recipe in the terminal" () (,read-cook recipe))) + (read "Read recipe in the terminal" () (,read-cook recipe)) + (html "Display recipe in HTML format" () (,html-cook recipe))) (,cook files ...)) (command-line)) diff --git a/cook/html.scm b/cook/html.scm new file mode 100644 index 0000000..0f8a501 --- /dev/null +++ b/cook/html.scm @@ -0,0 +1,35 @@ +;; TODO +(define (expand x) + (match x + (($ <note> text) + `(p ,text)) + (($ <section> name) + `(h1 ,name)) + (($ <step> elements) + `(li ,@(map expand elements))) + (($ <amount> quantity unit) + (list "(" (number->string quantity) unit ")")) + (($ (or <ingredient> <cookware> <timer>) name amount) + `(span ,@(if name (list name) '()) + ,@(if amount (expand amount) '()))) + (($ <recipe> metadata body) + `((@raw "<!DOCTYPE html>") + (html (body (ol ,@(expand body)))))) + ((? list? x) + (map expand x)) + ((? string? x) + x) + (else ""))) + +(define (recipe->html recipe) + (let ((ingredients (recipe-ingredients recipe)) + (cookware (recipe-cookware recipe)) + (timers (recipe-timers recipe))) + #;(for-each (lambda (x) + (display (ingredient-name x)) + (display ": ") + (when (ingredient-amount x) + (display (amount-quantity (ingredient-amount x))) + (display (amount-unit (ingredient-amount x)))) + (newline)) ingredients) + (sxml->xml (expand recipe)))) diff --git a/cook/html.sld b/cook/html.sld new file mode 100644 index 0000000..c40752f --- /dev/null +++ b/cook/html.sld @@ -0,0 +1,8 @@ +(define-library (cook html) + (import (scheme small) + (chibi match) + (chibi sxml) + (chibi string) + (cook parse-internals)) + (export recipe->html) + (include "html.scm")) |