source: tol/tolsh/tolsh.vfs/lib/tcllib1.10/doctools/mpformats/_html.tcl @ 8597867d

1941-docker-image-to-testdevel
Last change on this file since 8597867d was 8597867d, checked in by Jorge Pérez <josp.jorge@…>, 16 years ago

closes #976, se incluye tcllib1.10, base64 debe eliminarse del raiz de lib ya que esta incluido en tcllib

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@2556 be4846ae-f051-483a-831f-b64e7d08527f

  • Property mode set to 100644
File size: 4.8 KB
Line 
1# -*- tcl -*-
2# Helper rules for the creation of the memchan website from the .exp files.
3# General formatting instructions ...
4
5# htmlEscape text --
6#       Replaces HTML markup characters in $text with the
7#       appropriate entity references.
8#
9
10global textMap;
11set    textMap {
12    &    &amp;    <    &lt;     >    &gt;       
13    \xa0 &nbsp;   \xb0 &deg;    \xc0 &Agrave; \xd0 &ETH;    \xe0 &agrave; \xf0 &eth;
14    \xa1 &iexcl;  \xb1 &plusmn; \xc1 &Aacute; \xd1 &Ntilde; \xe1 &aacute; \xf1 &ntilde;
15    \xa2 &cent;   \xb2 &sup2;   \xc2 &Acirc;  \xd2 &Ograve; \xe2 &acirc;  \xf2 &ograve;
16    \xa3 &pound;  \xb3 &sup3;   \xc3 &Atilde; \xd3 &Oacute; \xe3 &atilde; \xf3 &oacute;
17    \xa4 &curren; \xb4 &acute;  \xc4 &Auml;   \xd4 &Ocirc;  \xe4 &auml;   \xf4 &ocirc;
18    \xa5 &yen;    \xb5 &micro;  \xc5 &Aring;  \xd5 &Otilde; \xe5 &aring;  \xf5 &otilde;
19    \xa6 &brvbar; \xb6 &para;   \xc6 &AElig;  \xd6 &Ouml;   \xe6 &aelig;  \xf6 &ouml;
20    \xa7 &sect;   \xb7 &middot; \xc7 &Ccedil; \xd7 &times;  \xe7 &ccedil; \xf7 &divide;
21    \xa8 &uml;    \xb8 &cedil;  \xc8 &Egrave; \xd8 &Oslash; \xe8 &egrave; \xf8 &oslash;
22    \xa9 &copy;   \xb9 &sup1;   \xc9 &Eacute; \xd9 &Ugrave; \xe9 &eacute; \xf9 &ugrave;
23    \xaa &ordf;   \xba &ordm;   \xca &Ecirc;  \xda &Uacute; \xea &ecirc;  \xfa &uacute;
24    \xab &laquo;  \xbb &raquo;  \xcb &Euml;   \xdb &Ucirc;  \xeb &euml;   \xfb &ucirc;
25    \xac &not;    \xbc &frac14; \xcc &Igrave; \xdc &Uuml;   \xec &igrave; \xfc &uuml;
26    \xad &shy;    \xbd &frac12; \xcd &Iacute; \xdd &Yacute; \xed &iacute; \xfd &yacute;
27    \xae &reg;    \xbe &frac34; \xce &Icirc;  \xde &THORN;  \xee &icirc;  \xfe &thorn;
28    \xaf &hibar;  \xbf &iquest; \xcf &Iuml;   \xdf &szlig;  \xef &iuml;   \xff &yuml;
29    {"} &quot;
30} ; # " make the emacs highlighting code happy.
31
32# Handling of HTML delimiters in content:
33#
34# Plain text is initially passed through unescaped;
35# internally-generated markup is protected by preceding it with \1.
36# The final PostProcess step strips the escape character from
37# real markup and replaces markup characters from content
38# with entity references.
39#
40
41global   markupMap
42set      markupMap { {&} {\1&}  {<} {\1<}  {>} {\1>} {"} {\1"} }
43global   finalMap
44set      finalMap $textMap
45lappend  finalMap {\1&} {&}  {\1<} {<}  {\1>} {>} {\1"} {"}
46
47
48proc htmlEscape {text} {
49    global textMap
50    return [string map $textMap $text]
51}
52
53proc fmt_postprocess {text}     {
54    global finalMap
55    return [string map $finalMap $text]
56}
57
58# markup text --
59#       Protect markup characters in $text with \1.
60#       These will be stripped out in PostProcess.
61#
62proc markup {text} {
63    global markupMap
64    return [string map $markupMap $text]
65}
66
67proc use_bg {} {
68    set c [bgcolor]
69    #puts stderr "using $c"
70    if {$c == {}} {return ""}
71    return bgcolor=$c
72}
73
74
75proc nbsp   {}         {return [markup "&nbsp;"]}
76proc p      {}         {return [markup <p>]}
77proc ptop   {}         {return [markup "<p valign=top>"]}
78proc td     {}         {return [markup "<td [use_bg]>"]}
79proc trtop  {}         {return [markup "<tr valign=top [use_bg]>"]}
80proc tr     {}         {return [markup "<tr            [use_bg]>"]}
81proc sect   {s}        {return [markup "<b>$s</b><br><hr>"]}
82proc link   {text url} {return [markup "<a href=\"$url\">$text</a>"]}
83proc table  {}         {return [markup "<table [border] width=100% cellspacing=0 cellpadding=0>"]}
84proc btable {}         {return [markup "<table border=1 width=100% cellspacing=0 cellpadding=0>"]}
85proc stable {}         {return [markup "<table [border] cellspacing=0 cellpadding=0>"]}
86
87
88proc tcl_cmd {cmd} {return "[markup <b>]\[$cmd][markup </b>]"}
89proc wget    {url} {exec /usr/bin/wget -q -O - $url 2>/dev/null}
90
91proc url {tag text url} {
92    set body {
93        switch -exact -- $what {
94            link {return {\1<a href="%url%"\1>%text%\1</a\1>}} ; ## TODO - markup
95            text {return {%text%}}
96            url  {return {%url%}}
97        }
98    }
99    proc $tag {{what link}} [string map [list %text% $text %url% $url] $body]
100}
101
102proc img {tag alt img} {
103    proc $tag {} [list return "\1<img alt=\"$alt\" src=\"$img\"\1>"]
104}
105
106proc protect {text} {return [string map [list & "&amp;" < "&lt;" > "&gt;"] $text]}
107
108
109proc tag  {t} {return [markup <$t>]}
110proc taga {t av} {
111    # av = attribute value ...
112    set avt [list]
113    foreach {a v} $av {lappend avt "$a=\"$v\""}
114    return [markup "<$t [join $avt]>"]
115}
116proc tag/ {t} {return [markup </$t>]}
117proc tag_ {t block args} {
118    # args = key value ...
119    if {$args == {}} {return "[tag $t]$block[tag/ $t]"}
120    return "[taga $t $args]$block[tag/ $t]"
121}
122
123
124proc ht_comment {text}   {return "[markup <]! -- [join [split $text \n] "   -- "]\n   --[markup >]"}
125
126# wrap content gi --
127#       Returns $content wrapped inside <$gi> ... </$gi> tags.
128#
129proc wrap {content gi} {
130    return "[tag $gi]${content}[tag/ $gi]"
131}
132proc startTag {x args} {if {[llength $args]} {taga $x $args} else {tag $x}}
133proc endTag   {x} {tag/ $x}
Note: See TracBrowser for help on using the repository browser.