1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
#
# XML
#
proc ::helpdoc::xml_escape_chr {content} {
# replace xml special characters by escape-characters
foreach {chr escChr} {
& {\&}
< {\<}
> {\>}
} {
regsub -all -- $chr $content $escChr content
}
regsub -all -- ' $content {\'} content
regsub -all -- \" $content {\"} content
return $content
}
proc ::helpdoc::xml_attr_escape_chr {content} {
# replace xml special characters by escape-characters
foreach {chr escChr} {
& {\&}
< {\<}
> {\>}
} {
regsub -all -- $chr $content $escChr content
}
return $content
}
proc ::helpdoc::xml_tag_enter {tag attr content depth} {
variable fid
set indent [indent $depth]
set sep ""
if { $content != "" } {
if { [llength [split $content \n]] > 1 } {
set content [trimEmpty $content]
set sep \n
} else {
set sep " "
}
}
set attr [xml_attr_escape_chr $attr]
set content [formatString [xml_escape_chr $content]]
if { $attr != "" } {
puts $fid(xml) "${indent}<$tag ${attr}>${sep}${content}"
} else {
puts $fid(xml) "${indent}<$tag>${sep}${content}"
}
}
proc ::helpdoc::xml_tag_leave {tag attr content depth} {
variable fid
puts $fid(xml) "[indent $depth]</$tag>"
}
|