_html.tcl

Go to the documentation of this file.
00001 /*  -*- tcl -*-*/
00002 /*  Helper rules for the creation of the memchan website from the .exp files.*/
00003 /*  General formatting instructions ...*/
00004 
00005 /*  htmlEscape text --*/
00006 /*  Replaces HTML markup characters in $text with the*/
00007 /*  appropriate entity references.*/
00008 /* */
00009 
00010 global textMap;
00011     textMap =  {
00012     &    &amp;    <    &lt;     >    &gt;       
00013     \xa0 &nbsp;   \xb0 &deg;    \xc0 &Agrave; \xd0 &ETH;    \xe0 &agrave; \xf0 &eth;
00014     \xa1 &iexcl;  \xb1 &plusmn; \xc1 &Aacute; \xd1 &Ntilde; \xe1 &aacute; \xf1 &ntilde;
00015     \xa2 &cent;   \xb2 &sup2;   \xc2 &Acirc;  \xd2 &Ograve; \xe2 &acirc;  \xf2 &ograve;
00016     \xa3 &pound;  \xb3 &sup3;   \xc3 &Atilde; \xd3 &Oacute; \xe3 &atilde; \xf3 &oacute;
00017     \xa4 &curren; \xb4 &acute;  \xc4 &Auml;   \xd4 &Ocirc;  \xe4 &auml;   \xf4 &ocirc;
00018     \xa5 &yen;    \xb5 &micro;  \xc5 &Aring;  \xd5 &Otilde; \xe5 &aring;  \xf5 &otilde;
00019     \xa6 &brvbar; \xb6 &para;   \xc6 &AElig;  \xd6 &Ouml;   \xe6 &aelig;  \xf6 &ouml;
00020     \xa7 &sect;   \xb7 &middot; \xc7 &Ccedil; \xd7 &times;  \xe7 &ccedil; \xf7 &divide;
00021     \xa8 &uml;    \xb8 &cedil;  \xc8 &Egrave; \xd8 &Oslash; \xe8 &egrave; \xf8 &oslash;
00022     \xa9 &copy;   \xb9 &sup1;   \xc9 &Eacute; \xd9 &Ugrave; \xe9 &eacute; \xf9 &ugrave;
00023     \xaa &ordf;   \xba &ordm;   \xca &Ecirc;  \xda &Uacute; \xea &ecirc;  \xfa &uacute;
00024     \xab &laquo;  \xbb &raquo;  \xcb &Euml;   \xdb &Ucirc;  \xeb &euml;   \xfb &ucirc;
00025     \xac &not;    \xbc &frac14; \xcc &Igrave; \xdc &Uuml;   \xec &igrave; \xfc &uuml;
00026     \xad &shy;    \xbd &frac12; \xcd &Iacute; \xdd &Yacute; \xed &iacute; \xfd &yacute;
00027     \xae &reg;    \xbe &frac34; \xce &Icirc;  \xde &THORN;  \xee &icirc;  \xfe &thorn;
00028     \xaf &hibar;  \xbf &iquest; \xcf &Iuml;   \xdf &szlig;  \xef &iuml;   \xff &yuml;
00029     {"} &quot;
00030 } ; /*  " make the emacs highlighting code happy.*/
00031 
00032 /*  Handling of HTML delimiters in content:*/
00033 /* */
00034 /*  Plain text is initially passed through unescaped;*/
00035 /*  internally-generated markup is protected by preceding it with \1.*/
00036 /*  The final PostProcess step strips the escape character from*/
00037 /*  real markup and replaces markup characters from content*/
00038 /*  with entity references.*/
00039 /* */
00040 
00041 global   markupMap
00042       markupMap =  { {&} {\1&}  {<} {\1<}  {>} {\1>} {"} {\1"} } 
00043 global   finalMap
00044       finalMap =  $textMap
00045 lappend  finalMap {\1&} {&}  {\1<} {<}  {\1>} {>} {\1"} {"}
00046 
00047 
00048 ret  htmlEscape (type text) {
00049     global textMap
00050     return [string map $textMap $text]
00051 }
00052 
00053 ret  fmt_postprocess (type text)    {
00054     global finalMap
00055     return [string map $finalMap $text]
00056 }
00057 
00058 /*  markup text --*/
00059 /*  Protect markup characters in $text with \1.*/
00060 /*  These will be stripped out in PostProcess.*/
00061 /* */
00062 ret  markup (type text) {
00063     global markupMap
00064     return [string map $markupMap $text]
00065 }
00066 
00067 ret  use_bg () {
00068     set c [bgcolor]
00069     #puts stderr "using $c"
00070     if {$c == {}} {return ""}
00071     return bgcolor=$c
00072 }
00073 
00074 
00075 ret  nbsp   ()         {return [markup "&nbsp;"]}
00076 ret  p      ()         {return [markup <p>]}
00077 ret  ptop   ()         {return [markup "<p valign=top>"]}
00078 ret  td     ()         {return [markup "<td [use_bg]>"]}
00079 ret  trtop  ()         {return [markup "<tr valign=top [use_bg]>"]}
00080 ret  tr     ()         {return [markup "<tr            [use_bg]>"]}
00081 ret  sect   (type s)        {return [markup "<b>$s</b><br><hr>"]}
00082 ret  link   (type text , type url) {return [markup "<a href=\"$url\">$text</a>"]}
00083 ret  table  ()         {return [markup "<table [border] width=100% cellspacing=0 cellpadding=0>"]}
00084 ret  btable ()         {return [markup "<table border=1 width=100% cellspacing=0 cellpadding=0>"]}
00085 ret  stable ()         {return [markup "<table [border] cellspacing=0 cellpadding=0>"]}
00086 
00087 
00088 ret  tcl_cmd (type cmd) {return "[markup <b>]\[$cmd][markup </b>]"}
00089 ret  wget    (type url) {exec /usr/bin/wget -q -O - $url 2>/dev/null}
00090 
00091 ret  url (type tag , type text , type url) {
00092     set body {
00093     switch -exact -- $what {
00094         link {return {\1<a href="%url%"\1>%text%\1</a\1>}} ; ## TODO - markup
00095         text {return {%text%}}
00096         url  {return {%url%}}
00097     }
00098     }
00099     proc $tag {{what link}} [string map [list %text% $text %url% $url] $body]
00100 }
00101 
00102 ret  img (type tag , type alt , type img) {
00103     proc $tag {} [list return "\1<img alt=\"$alt\" src=\"$img\"\1>"]
00104 }
00105 
00106 ret  protect (type text) {return [string map [list & "&amp;" < "&lt;" > "&gt;"] $text]}
00107 
00108 
00109 ret  tag  (type t) {return [markup <$t>]}
00110 ret  taga (type t , type av) {
00111     # av = attribute value ...
00112     set avt [list]
00113     foreach {a v} $av {lappend avt "$a=\"$v\""}
00114     return [markup "<$t [join $avt]>"]
00115 }
00116 ret  tag/ (type t) {return [markup </$t>]}
00117 ret  tag_ (type t , type block , type args) {
00118     # args = key value ...
00119     if {$args == {}} {return "[tag $t]$block[tag/ $t]"}
00120     return "[taga $t $args]$block[tag/ $t]"
00121 }
00122 
00123 
00124 ret  ht_comment (type text)   {return "[markup <]! -- [join [split $text \n] "   -- "]\n   --[markup >]"}
00125 
00126 /*  wrap content gi --*/
00127 /*  Returns $content wrapped inside <$gi> ... </$gi> tags.*/
00128 /* */
00129 ret  wrap (type content , type gi) {
00130     return "[tag $gi]${content}[tag/ $gi]"
00131 }
00132 ret  startTag (type x , type args) {if {[llength $args]} {taga $x $args} else {tag $x}}
00133 ret  endTag   (type x) {tag/ $x}
00134 

Generated on 21 Sep 2010 for Gui by  doxygen 1.6.1