source: tol/tolbase/lib/toltk/markuphelper.tcl @ 4c5e200

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

fixes #1414, escapamos los cambios de línea al mostrar el contenido, el cambio de comportamiento se introdujo con el cambio de widget info.

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

  • Property mode set to 100644
File size: 4.1 KB
Line 
1namespace eval ::MarkupHelper {
2  variable markup
3
4  proc Init { } {
5    variable markup {}
6  }
7
8  proc Verbatim { text } {
9    return [ string map {\n \n<br>} $text ]
10  }
11
12  proc Escape { text } {
13    set specialChars {
14      [  &lb;
15      ]  &rb;
16      <  &lt;
17      >  &gt;
18      '  &ap;
19      &  &amp;
20    }
21    return [ string map $specialChars $text ]
22  }
23
24  proc Preprocess { text } {
25    set idx [ string first ";" $text ]
26    set ismarkup 0
27    if { $idx != -1 } {
28      set header [ string range $text 0 [ expr { $idx -1 } ] ]
29      if { [ string range [ string trimleft $header ] 0 3 ] eq "#!NB" } {
30        set ismarkup 1
31        set body [ string range $text [ expr { $idx +1 } ] end ]
32      } else {
33        set body $text
34      }
35    } else {
36      set body $text
37    }
38    if { $ismarkup } {
39      return $body
40    } else {
41      return [ Verbatim [ Escape $body ] ]
42    }
43  }
44
45  proc GetText { } {
46    variable markup
47
48    return $markup
49  }
50
51  proc Text { text args } {
52    variable markup
53
54    array set opts { -tags {} -br 0 }
55    array set opts $args
56    foreach t $opts(-tags) {
57      append markup "<$t>"
58    }
59    append markup $text
60    foreach t [ lreverse $opts(-tags) ] {
61      append markup "</$t>"
62    }
63    BR $opts(-br)
64  }
65
66  proc Image { image {br 0} } {
67    variable markup
68
69    append markup "\[!image $image !\]"
70    BR $br
71  }
72
73  proc LabelValue { name value {br 0}} {
74    variable markup
75
76    append markup "<b>$name:</b> "
77    append markup "$value"
78    BR $br
79  }
80 
81  proc InlineHeader { text } {
82    Text $text -tags h
83  }
84
85  proc Header1 { text } {
86    variable markup
87   
88    NeedNewLine
89    append markup "= $text =\n"
90  }
91
92  proc Header2 { text } {
93    variable markup
94   
95    append markup "\n\n== $text ==\n"
96  }
97
98  proc Header3 { text } {
99    variable markup
100   
101    append markup "\n\n=== $text ===\n"
102  }
103
104  proc BR { { br 1 } } {
105    variable markup
106
107    if { $br } {
108      append markup " <br>"
109    }
110  }
111
112  proc NeedNewLine { } {
113    variable markup
114
115    if { [ string index $markup end ] ne "\n" } {
116      append markup "\n"
117    }
118  }
119   
120  proc Line { } {
121    variable markup
122
123    if { [ string index $markup end ] ne "\n" } {
124      append markup "\n"
125    }
126    append markup "#---\n"
127  }
128
129  # esto deberia recibir un ObjectAddress
130  proc BuildTolbaseInfo {icon grammar name content path desc args } {
131    array set opts $args
132
133    foreach {classOf insInfo insCont} {{} {} {}} break
134    if { $grammar eq "NameBlock" } {
135      if { [ info exists opts(-objref) ] } {
136        set objRef $opts(-objref)
137        set classOf [Tol_ClassOfFromReference $objRef]
138        set insInfo [Tol_InstanceInfoFromReference $objRef]
139        set insCont [Tol_InstanceContentFromReference $objRef]
140      } elseif { [ info exists opts(-objaddr) ] } {
141        set objAddr $opts(-objaddr)
142        set classOf [Tol_ClassOf $objAddr]
143        set insInfo [Tol_InstanceInfo $objAddr]
144        set insCont [Tol_InstanceContent $objAddr]
145      }
146    }
147    Text "Grammar: " -tags b
148    Image $icon
149    if {$classOf eq ""} {
150      Text " $grammar"
151    } else {
152      Text " $classOf"
153    }
154    BR
155    LabelValue "Name" $name
156    if {$insCont ne ""} {
157      set _content $insCont
158    } elseif {$classOf ne ""} {
159      set _content $classOf
160    } else {
161      set _content $content
162    }
163    BR
164    LabelValue "Content" [ Verbatim [ Escape $_content ] ]
165    if {$path ne ""} {
166      BR
167      LabelValue "Path" $path
168    }
169    if {$desc ne ""} {
170      BR
171      Text "Description:" -tags b -br 1
172      Text \
173          [ Preprocess [ string trimright $desc ] ]
174    }
175    if { $insInfo ne "" } {
176      Header2 "Instance's Info"
177      foreach line [ split $insInfo \n ] {
178        set s [ string index $line 0 ]
179        set e [ string index $line end ]
180        if { $s eq "\[" && $e eq "\]" } {
181          Text "[ string range $line 1 end-1 ]:" \
182              -tags {b} -br 1
183        } elseif { $s eq "{" && $e eq "}" } {
184          Text "[ string range $line 1 end-1 ]: " -tags {b}
185        } else {
186          Text \
187              [ Preprocess [ string trimright $line ] ] -br 1
188        }
189      }
190    }
191    return [ GetText ]
192  }
193}
Note: See TracBrowser for help on using the repository browser.