xo::api proc source_to_html (public)
xo::api source_to_html [ -width width ] string
Defined in packages/xotcl-core/tcl/01-debug-procs.tcl
Helper proc to preserve indentation in source-code to HTML conversion.
- Switches:
- -width (optional, defaults to
"100"
)- Parameters:
- string (required)
- Testcases:
- No testcase defined.
Source code: # # Helper proc to preserve indentation in source-code to HTML # conversion. # set lines [list] foreach l [split $string \n] { while {[string length $l] > $width} { set pos [string last " \{" $l $width] if {$pos>10} { lappend lines "[string range $l 0 $pos-1] \\" set l " [string range $l $pos end]" } else { # search for a match right of the target set pos [string first " \{" $l $width] if {$pos > 10} { lappend lines "[string range $l 0 $pos-1] \\" set l " [string range $l $pos end]" } else { # last resort try to split around spaces set pos [string last " " $l $width] if {$pos > 10} { lappend lines "[string range $l 0 $pos-1] \\" set l " [string range $l $pos end]" } else { break } } } } lappend lines $l } set string [join $lines \n] set html [ns_quotehtml $string] regsub -all -- {(\n[\t ]*)(\#[^\n]*)} $html \\1<it>\\2</it> html return "<pre class='code'>$html</pre>"XQL Not present: Generic, PostgreSQL, Oracle