== Extending tcl to generate html == [CMcC] Following from [jenglish]'s comment: why learn to use a monster [HTML]-template library when you can, with a few lines of code, extend the base language so you can write things like [[ href "/home.html" { ! "Home" }]] ... I wrote the following to do just that using the techniques in [let unknown know]. ---- package provide know 1.0 proc know {cond body} { if {![info complete $body]} {error "incomplete command(s) $body"} proc unknown {args} [string map [list @c@ $cond @b@ $body] { if {![catch {expr {@c@}} res] && $res} { return [eval {@b@}] } }][info body unknown] } ;# RS ---- package require know know {[string match <*> [lindex $args 0]]} { set tag [string trim [lindex $args 0] "<>"] ::proc ::<$tag> {args} [string map [list @T $tag] { set result {} foreach {n v} [lrange $args 0 end-1] { lappend result "$n='[armour $v]'" } return "<@T [join ${result}]>[lindex $args end]" }] return [eval $args] } ---- ''[escargo] 7 Jun 2007'' - Is there really a "know" package available somewhere, or is this just presupposing that code from [let unknown know] has been sourced in somewhere? [CMcC] the latter. -- ''[escargo]'' - Perhaps you would be kind enough to paste in the version you require. I'd like to use [wish-reaper] to take all of the source from one place and then give it a bit of exercise. ---- This will generate a proc for any command like [[
  • ]] which will do pretty much what you'd expect it to. It could be extended to handle something like: [[ {tr-alist} {td-alist} args] which would use the [join] trickery below to generate a table row. [[