1# -*- tcl -*-
2#
3# Copyright (c) 2019 Andreas Kupries <andreas_kupries@sourceforge.net>
4# Freely redistributable.
5#
6# _text_para.tcl -- Paragraph variables and accessors - Text accumulator
7
8# # ## ### ##### ########
9## State: Text buffer for paragraphs.
10
11global __currentp
12
13# # ## ### ##### ########
14## API
15
16proc Text {text} {
17    #puts_stderr "T++ (($text))"
18    global __currentp
19    append __currentp $text
20    return
21}
22proc Text?     {} { global __currentp ; return $__currentp }
23proc TextClear {} { global __currentp ; set __currentp "" }
24
25proc TextTrimLeadingSpace {} {
26    global __currentp
27    regsub {^([ \t\v\f]*\x01?\n)*} $__currentp {} __currentp
28    return
29}
30
31proc TextTrimTrailingSpace {} {
32    global __currentp
33    regsub {([ \t\v\f]*\x01?\n)*$} $__currentp {} __currentp
34    append __currentp \n
35    return
36}
37
38proc TextPlain {text} {
39    if  {[IsOff]} {return}
40
41    # Note: Whenever we get plain text it is possible that a macro for
42    # visual markup actually generated output before the expander got
43    # to the current text. This output was captured by the expander in
44    # its current context. Given the current organization of the
45    # engine we have to retrieve this formatted text from the expander
46    # or it will be lost. This is the purpose of the 'ctopandclear',
47    # which retrieves the data and also clears the capture buffer. The
48    # latter to prevent us from retrieving it again later, after the
49    # next macro added more data.
50
51    set text [ex_ctopandclear]$text
52
53    #puts_stderr "<<text_plain_text>>=<<[string map [list \t \\t { } \\s \n \\n \r \\r \v \\v \f \\f \1 \\1] $text]>>"
54
55    # ... TODO ... Handling of example => verbatim
56
57    if {[string length [string trim $text]] == 0} return
58
59    Text $text
60    return
61}
62
63##
64# # ## ### ##### ########
65return
66