Exercises in this lecture   Go to the notes, in which this exercise belongs -- Keyboard shortcut: 'u'   Alphabetic index   Course home   

Exercise solution 2
A color-text function


(load (string-append laml-dir "laml.scm"))
(laml-style "simple-xhtml1.0-transitional-validating")
; (lib-load "xhtml1.0-convenience.scm")

(define color-text
  (xml-in-laml-positional-abstraction  3 0 
    (lambda (r g b cont attr)
      (span 'css:color  (rgb-color-encoding r g b) cont attr))))

(define other-color-text
  (xml-in-laml-abstraction
    (lambda (cont attr)
       (let ((r (as-number (get-prop 'red attr)))
             (g (as-number (get-prop 'green attr)))
             (b (as-number (get-prop 'blue attr))))
        (span 'css:color 
          (rgb-color-encoding  r g b) cont (but-props attr '(red green blue)))))))

(define current-xml-language 'xhtml10-transitional)
(define laml-generation-meta (meta 'name "Generator" 'content "LAML"))
(define meta-props (list 'http-equiv "Content-Type" 'content "text/html; charset=iso-8859-1"))
(define html-props (list 'xmlns "http://www.w3.org/1999/xhtml"))

(write-html '(raw prolog)
 (html html-props
  (head 
   (meta meta-props) laml-generation-meta
   (title "TITLE"))
  (body 
  
    (p "Here is some" (color-text 0 255 0 "Very" "interesting color text" _ "."))

    (p "Here is some other"
       (other-color-text 'red "255" 'green "0" 'blue "255" "Very" "interesting color text" _ "."))
  

  )
 )
)


(end-laml)