ad_html_to_text_put_text (private)

 ad_html_to_text_put_text output_var text

Defined in packages/acs-tcl/tcl/text-html-procs.tcl

Helper proc for ad_html_to_text

Parameters:
output_var
text
Authors:
Lars Pind <lars@pinds.com>
Aaron Swartz <aaron@swartzfam.com>
Created:
19 July 2000

Partial Call Graph (max 5 caller/called nodes):
%3 ad_html_to_text ad_html_to_text (public) ad_html_to_text_put_text ad_html_to_text_put_text ad_html_to_text->ad_html_to_text_put_text acs::icanuse acs::icanuse (public) ad_html_to_text_put_text->acs::icanuse ad_html_to_text_put_newline ad_html_to_text_put_newline (private) ad_html_to_text_put_text->ad_html_to_text_put_newline

Testcases:
No testcase defined.
Source code:
    upvar $output_var output

    # Expand entities before outputting
    set text [ns_unquotehtml $text]

    #
    # If we're not inside an HTML "<PRE>" element.
    #
    if { $output(pre) <= 0 } {
        # collapse all whitespace
        regsub -all -- {\s+} $text { } text

        # if there's only spaces in the string, wait until later
        if {$text eq " "} {
            set output(space) 1
            return
        }

        # if it's nothing, do nothing
        if { $text eq "" } {
            return
        }

        # if the first character is a space, set the space bit
        if {[string index $text 0] eq " "} {
            set output(space) 1
            set text [string trimleft $text]
        }
    } else {
        #
        # We're inside an HTML <PRE> element: clean line breaks
        # and tabs.
        #
        regsub -all -- {\r\n} $text "\n" text
        regsub -all -- {\r} $text "\n" text
        # tabs become four spaces
        regsub -all -- {[\v\t]} $text {    } text
    }

    # output any pending paragraph breaks, line breaks or spaces.
    # as long as we're not at the beginning of the document
    if { $output(p) || $output(br) || $output(space) } {
        if { $output(text) ne "" } {
            if { $output(p) } {
                ad_html_to_text_put_newline output
                ad_html_to_text_put_newline output
            } elseif$output(br) } {
                ad_html_to_text_put_newline output
            } else {
                # Don't add the space if we're at the beginning of a line,
                # unless we're in a PRE
                if { $output(pre) > 0 || $output(linelen) != 0 } {
                    append output(text) " "
                    incr output(linelen)
                }
            }
        }
        set output(p) 0
        set output(br) 0
        set output(space) 0
    }

    # if the last character is a space, save it until the next time
    if { [regexp {^(.*) $} $text match text] } {
        set output(space) 1
    }


    if {[::acs::icanuse "ns_reflow_text -offset"]} {
        #
        # Reflow based on "ns_reflow_text -offset". This is
        # substantially faster, especially on longer text strings.
        #
        set plain [ns_reflow_text  -offset $output(linelen)  -width $output(maxlen)  -- $text]
        #ns_log notice "XXXX -> <$plain>"
        set lastNewLine [string last \n $plain]
        if {$lastNewLine == -1} {
            incr output(linelen) [string length $plain]
        } else {
            set output(linelen) [expr {[string length $plain] - $lastNewLine}]
        }
        set plain [join [split $plain \n] \n[string repeat {    } $output(blockquote)]]
        #ns_log notice "plain\n$plain"
        #ns_log notice "blockquote $output(blockquote) linelen $output(linelen) maxlen $output(maxlen)"
        append output(text) $plain

    } else {
        #
        # If there's a blockquote in the beginning of the text, we
        # wouldn't have caught it before.
        #
        if { $output(text) eq "" } {
            append output(text) [string repeat {    } $output(blockquote)]
        }

        # Now output the text.
        while { [regexp {^( +|\s|\S+)(.*)$} $text match word text] } {

            # convert &nbsp;'s
            # We do this now, so that they're displayed, but not treated, whitespace.
            regsub -all -- {&nbsp;} $word { } word

            set wordlen [string length $word]
            switch -glob -- $word {
                " *" {
                    append output(text) "$word"
                    incr output(linelen) $wordlen
                }
                "\n" {
                    if { $output(text) ne "" } {
                        ad_html_to_text_put_newline output
                    }
                }
                default {
                    if { $output(linelen) + $wordlen > $output(maxlen) && $output(maxlen) != 0 } {
                        ad_html_to_text_put_newline output
                    }
                    append output(text) "$word"
                    incr output(linelen) $wordlen
                }
            }
        }
    }
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: