# ACTIVESTATE TEAPOT-PKG BEGIN TM -*- tcl -*- # -- Tcl Module # @@ Meta Begin # Package doctools::html 0.1 # Meta as::build::date 2015-05-25 # Meta as::origin http://sourceforge.net/projects/tcllib # Meta license BSD # Meta platform tcl # Meta require {Tcl 8.4} # Meta require doctools::text # @@ Meta End # ACTIVESTATE TEAPOT-PKG BEGIN REQUIREMENTS package require Tcl 8.4 package require doctools::text # ACTIVESTATE TEAPOT-PKG END REQUIREMENTS # ACTIVESTATE TEAPOT-PKG BEGIN DECLARE package provide doctools::html 0.1 # ACTIVESTATE TEAPOT-PKG END DECLARE # ACTIVESTATE TEAPOT-PKG END TM # -*- tcl -*- # Copyright (c) 2009 Andreas Kupries # Support package. Basic html generation commands. # # ## ### ##### ######## ############# ##################### ## Requirements package require Tcl 8.4 ; # Required Core package require doctools::text ; # Basic generator state management. namespace eval ::doctools::html {} doctools::text::import ::doctools::html # # ## ### ##### ######## ############# ##################### proc ::doctools::html::begin {} { text::begin Begin return } proc ::doctools::html::save {} { variable state set current [array get state] text::save Begin set state(stack) $current return } proc ::doctools::html::restore {} { variable state set html [text::restore] array set state $state(stack) return $html } proc ::doctools::html::collect {script} { save uplevel 1 $script return [restore] } # # ## ### ##### ######## ############# ##################### proc ::doctools::html::tag1 {name args} { text::+ <$name if {[llength $args]} { foreach {a v} $args { text::+ " $a=\"$v\"" } } text::+ > return } proc ::doctools::html::tag {name args} { tagD $name $args return } proc ::doctools::html::tagD {name dict} { variable state lappend state(tstack) $name text::+ <$name if {[llength $dict]} { foreach {a v} $dict { text::+ " $a=\"$v\"" } } text::+ > return } proc ::doctools::html::/tag {} { variable state set tag [lindex $state(tstack) end] set state(tstack) [lreplace $state(tstack) end end] text::+ return } proc ::doctools::html::tag/ {name args} { variable state lappend state(tstack) $tag text::+ <$tag if {[llength $args]} { foreach {a v} $args { text::+ " $a=\"$v\"" } text::+ { } } text::+ /> return } proc ::doctools::html::tag* {name args} { set script [lindex $args end] set args [lreplace $args end end] tagD $name $args uplevel 1 $script /tag return } proc ::doctools::html::tag= {name args} { set text [lindex $args end] set args [lreplace $args end end] eval [linsert $args 0 tag $name] + $text /tag return } # # ## ### ##### ######## ############# ##################### proc ::doctools::html::+ {text} { text::+ [Quote $text] return } proc ::doctools::html::comment {comment} { text::+ "" return } proc ::doctools::html::++ {html} { text::+ $html return } # # ## ### ##### ######## ############# ##################### proc ::doctools::html::import {{namespace {}}} { uplevel 1 [list namespace eval ${namespace}::html { namespace import ::doctools::html::* }] return } proc ::doctools::html::importhere {{namespace ::}} { uplevel 1 [list namespace eval ${namespace} { namespace import ::doctools::html::* }] return } # # ## ### ##### ######## ############# ##################### proc ::doctools::html::Begin {} { variable state array unset state * array set state { tags {} stack {} } return } proc ::doctools::html::Quote {text} { variable textMap return [string map $textMap $text] } # # ## ### ##### ######## ############# ##################### namespace eval ::doctools::html { variable state array set state {} # Replaces HTML markup characters in $text with the appropriate # entity references. variable textMap { & & < < > > \xa0   \xb0 ° \xc0 À \xd0 Ð \xe0 à \xf0 ð \xa1 ¡ \xb1 ± \xc1 Á \xd1 Ñ \xe1 á \xf1 ñ \xa2 ¢ \xb2 ² \xc2 Â \xd2 Ò \xe2 â \xf2 ò \xa3 £ \xb3 ³ \xc3 Ã \xd3 Ó \xe3 ã \xf3 ó \xa4 ¤ \xb4 ´ \xc4 Ä \xd4 Ô \xe4 ä \xf4 ô \xa5 ¥ \xb5 µ \xc5 Å \xd5 Õ \xe5 å \xf5 õ \xa6 ¦ \xb6 ¶ \xc6 Æ \xd6 Ö \xe6 æ \xf6 ö \xa7 § \xb7 · \xc7 Ç \xd7 × \xe7 ç \xf7 ÷ \xa8 ¨ \xb8 ¸ \xc8 È \xd8 Ø \xe8 è \xf8 ø \xa9 © \xb9 ¹ \xc9 É \xd9 Ù \xe9 é \xf9 ù \xaa ª \xba º \xca Ê \xda Ú \xea ê \xfa ú \xab « \xbb » \xcb Ë \xdb Û \xeb ë \xfb û \xac ¬ \xbc ¼ \xcc Ì \xdc Ü \xec ì \xfc ü \xad ­ \xbd ½ \xcd Í \xdd Ý \xed í \xfd ý \xae ® \xbe ¾ \xce Î \xde Þ \xee î \xfe þ \xaf &hibar; \xbf ¿ \xcf Ï \xdf ß \xef ï \xff ÿ {"} " } ; # " make the emacs highlighting code happy. # Text commands which are html commands, unchanged namespace import \ ::doctools::text::done \ ::doctools::text::+++ \ ::doctools::text::newline \ ::doctools::text::prefix \ ::doctools::text::indent \ ::doctools::text::dedent \ ::doctools::text::indented \ ::doctools::text::indenting \ ::doctools::text::newlines namespace export begin done save restore collect + +++ \ prefix indent dedent indented indenting newline newlines \ tag /tag tag/ tag* tag1 tag= comment ++ } # # ## ### ##### ######## ############# ##################### package provide doctools::html 0.1 return