| 1 | # -*- tcl -*- |
|---|
| 2 | # |
|---|
| 3 | # $Id: toc.text,v 1.7 2005/09/28 04:51:19 andreas_kupries Exp $ |
|---|
| 4 | # |
|---|
| 5 | # Engine to convert a doctoc document into plain text. |
|---|
| 6 | # |
|---|
| 7 | # Copyright (c) 2003 Andreas Kupries <andreas_kupries@sourceforge.net> |
|---|
| 8 | # Freely redistributable. |
|---|
| 9 | # |
|---|
| 10 | ###################################################################### |
|---|
| 11 | |
|---|
| 12 | dt_source _toc_common.tcl |
|---|
| 13 | dt_source _text.tcl |
|---|
| 14 | |
|---|
| 15 | ###################################################################### |
|---|
| 16 | # Conversion specification. |
|---|
| 17 | # One-pass processing. |
|---|
| 18 | |
|---|
| 19 | rename toc_postprocess {} |
|---|
| 20 | rename text_postprocess toc_postprocess |
|---|
| 21 | |
|---|
| 22 | proc fmt_plain_text {text} {return {}} |
|---|
| 23 | |
|---|
| 24 | ################################################################ |
|---|
| 25 | ## Backend for TMML markup |
|---|
| 26 | |
|---|
| 27 | global seclist ; set seclist {} |
|---|
| 28 | global max ; set max 0 |
|---|
| 29 | |
|---|
| 30 | proc fmt_comment {text} {return} |
|---|
| 31 | proc fmt_toc_end {} {return} |
|---|
| 32 | proc fmt_toc_begin {label title} { |
|---|
| 33 | TextInitialize |
|---|
| 34 | |
|---|
| 35 | set title "$label -- $title" |
|---|
| 36 | set hdr "" |
|---|
| 37 | append hdr "Table of contents [textutil::uncap [c_provenance]]\n" |
|---|
| 38 | append hdr \n |
|---|
| 39 | append hdr $title \n |
|---|
| 40 | append hdr [textutil::strRepeat = [string length $title]] |
|---|
| 41 | Text $hdr |
|---|
| 42 | CloseParagraph [Verbatim] |
|---|
| 43 | } |
|---|
| 44 | proc fmt_division_start {title symfile} { |
|---|
| 45 | global lmarginIncrement currentEnv |
|---|
| 46 | global seclist ; set seclist {} |
|---|
| 47 | global max ; set max 0 |
|---|
| 48 | |
|---|
| 49 | Text $title\n |
|---|
| 50 | Text [textutil::strRepeat - [string length $title]] |
|---|
| 51 | CloseParagraph [Verbatim] |
|---|
| 52 | SaveContext |
|---|
| 53 | NewEnv Division { |
|---|
| 54 | incr currentEnv(lmargin) $lmarginIncrement |
|---|
| 55 | } |
|---|
| 56 | return |
|---|
| 57 | } |
|---|
| 58 | proc fmt_division_end {} { |
|---|
| 59 | global seclist max |
|---|
| 60 | |
|---|
| 61 | if {[llength $seclist] > 0} { |
|---|
| 62 | set break 0 |
|---|
| 63 | incr max 2 |
|---|
| 64 | set rmargin [expr {80 - $max}] |
|---|
| 65 | if {$rmargin < 20} {set rmargin 20} |
|---|
| 66 | set pfx [textutil::blank $max] |
|---|
| 67 | incr max -1 |
|---|
| 68 | set fpfx "[textutil::strRepeat . $max] " |
|---|
| 69 | |
|---|
| 70 | foreach {file desc} $seclist { |
|---|
| 71 | set opfx "$file [string range $fpfx [string length $file] end]" |
|---|
| 72 | Text $opfx[textutil::indent [textutil::adjust $desc -length $rmargin] $pfx 1] |
|---|
| 73 | CloseParagraph [Verbatim] |
|---|
| 74 | } |
|---|
| 75 | set seclist {} |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | RestoreContext |
|---|
| 79 | return |
|---|
| 80 | } |
|---|
| 81 | proc fmt_item {file label desc} { |
|---|
| 82 | global seclist max |
|---|
| 83 | lappend seclist $file $desc |
|---|
| 84 | if {[string length $file] > $max} {set max [string length $file]} |
|---|
| 85 | return |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | ################################################################ |
|---|