Updated 2013-05-19 00:08:49 by aspect

WJG (18/05/13) The Gnocl widget set allows complex markup strings to be applied to label entries etc., through the use of the Pango markup language. This is useful but has can be meddlesome when long string are to be marked up. Pango recognizes the common HTML convenience tags and its easy to 'extend' this capability by adding custom alternatives. Before passing onto any markup-enabled widget strings can be mapped and expanded to the required settings.
#---------------
# test-markup.tcl
#---------------

#!/bin/sh
#\
exec tclsh "$0" "$@"

package require Gnocl

#---------------
# extend the range of convenience tags
#---------------
#
proc expand_tags {str} {

        set map {
                <r> {<span foreground='red'>} </r> </span>
                <e> {<span underline='error' underline_color='red'>} </e> </span> 
                <d> {<span underline='double' underline_color='blue'>} </d> </span> 
                }

        return [string map $map $str ]
}

set str "<r>Gnocl Text Markup</r>\n<e>Expanding Convenience Tags</e>\n<d>Using String Mapping</d>"

puts "before: $str"
puts "after [expand_tags $str]"

set label [gnocl::label -text [expand_tags $str] ]

gnocl::window \
    -title "Label" \
    -child $label \
    -width 100 \
    -height 25

aspect - I have found myself using a simple technique that has some of the readability benefits of the above:
set span_red {<span foreground=red>}
set span_err {<span underline=error underline_color=red>}
set {/span}  {</span>}
set label "${span_red}Text markup${/span} .. ${span_err}with tags${/span}"