add html parser
This commit is contained in:
parent
1db904e6a1
commit
98648ee163
71
html.scm
Normal file
71
html.scm
Normal file
|
@ -0,0 +1,71 @@
|
|||
(define html-wrap
|
||||
(lambda (body)
|
||||
(string-append "<html><head><meta charset=\"UTF-8\"></head><body>"
|
||||
body
|
||||
"<body></html>"
|
||||
)))
|
||||
|
||||
(define html-wrap-list
|
||||
(lambda (list-html)
|
||||
(string-append "<ul>"
|
||||
list-html
|
||||
"</ul>"
|
||||
)))
|
||||
|
||||
(define cookbook-as-html
|
||||
(lambda (cookbook)
|
||||
(cookbook-as-html-rec cookbook "")))
|
||||
|
||||
(define cookbook-as-html-rec
|
||||
(lambda (cookbook html)
|
||||
(if (null? cookbook)
|
||||
html
|
||||
(let ((recipe (car cookbook)))
|
||||
(cookbook-as-html-rec (cdr cookbook)
|
||||
(string-append html
|
||||
(recipe-as-html recipe)
|
||||
"<br>")))
|
||||
)))
|
||||
|
||||
(define recipe-as-html
|
||||
(lambda (recipe)
|
||||
(string-append "<h2>"
|
||||
(title recipe)
|
||||
"</h2>"
|
||||
"<i>Ingredients</i><br>"
|
||||
(ingredients-as-html (ingredients recipe))
|
||||
"<br><i>Steps</i><br>"
|
||||
(steps-as-html (steps recipe))
|
||||
"<br>")))
|
||||
|
||||
(define pretty-ingredient
|
||||
(lambda (ingredient)
|
||||
(let* ((name (ingredient-name ingredient))
|
||||
(amount (number->string (ingredient-amount ingredient)))
|
||||
(unit (ingredient-unit ingredient)))
|
||||
(string-append amount
|
||||
" "
|
||||
unit
|
||||
" "
|
||||
name))))
|
||||
|
||||
(define ingredients-as-html
|
||||
(lambda (ingredients)
|
||||
(list-as-html (map (lambda (x) (pretty-ingredient x)) ingredients))))
|
||||
|
||||
(define steps-as-html
|
||||
(lambda (steps)
|
||||
(list-as-html steps)))
|
||||
|
||||
(define list-as-html
|
||||
(lambda (list)
|
||||
(html-wrap-list (list-as-html-rec list ""))))
|
||||
|
||||
(define list-as-html-rec
|
||||
(lambda (list html)
|
||||
(if (null? list)
|
||||
html
|
||||
(list-as-html-rec (cdr list) (string-append html
|
||||
"<li>"
|
||||
(car list)
|
||||
"</li>\n")))))
|
Loading…
Reference in New Issue
Block a user