Tcl Library Source Code

Check-in [a75ee706ed]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Text: Fixed paragraph counting when nesting lists
Timelines: family | ancestors | descendants | both | doc-fixup-and-markdown
Files: files | file ages | folders
SHA3-256: a75ee706ed04a918984c791d4350d9d80aace0d4586aac2337ab6863ad83b8c9
User & Date: andreask 2019-03-19 23:45:27
Context
2019-03-19
23:46
Markdown: Fixed paragraph counting when nesting lists. Fix for indenting in progress. check-in: d5f39d22eb user: andreask tags: doc-fixup-and-markdown
23:45
Text: Fixed paragraph counting when nesting lists check-in: a75ee706ed user: andreask tags: doc-fixup-and-markdown
23:42
Continued markdown work. More test cases, nested lists. Demonstrate issues with paragraph counting (text & markdown) and indenting (markdown only). Possibly demonstrate issue with text and markdown when a nested list is the first paragraph of an entry, without preceding text. This looks to lose the outer markup for start of entry. check-in: eaa4c90a8c user: andreask tags: doc-fixup-and-markdown
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to modules/doctools/mpformats/fmt.text.

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
..
53
54
55
56
57
58
59

60
61
62
63
64
65
66
...
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152



153




















154
155
156
157
158
159
160
161
162
163
164

165
166
167

168

169
170
171
172
173
174
175
176

177
178
179
180
181
182
183

184
185
186

187

188
189
190
191
192
193

194
195

196
197
198
199
200
201
202
...
262
263
264
265
266
267
268
269




270
271
272
273
274
275
276
...
310
311
312
313
314
315
316
317
318
319

320
321
322

323
324

325
326
327
328
329


330
331
332
333

334
335
336
337
338
339
340
341
342
343

344
345
346
347
348
349
350
351
352
353


354
355
356
357
358
359
360


361
362
363
364
365
366
367
368
...
390
391
392
393
394
395
396
397







398
399
400

401
402
403
404
405
406
407
408
409
410

411
412
413
414

415
416


417
418
419
420
421
422
423
# # ## ### ##### ########
## Special manpage contexts

# example     = if present, context is for an example
# exenv       = if present, reference to example variant of current context

proc Example!     {} { CAttrSet example . }
proc Example?  {} { CAttrHas example }

proc NewExample {} {
    return [ContextNew Example { VerbatimOn ; Example! ; Prefix! "| " }] ; # {}
}

proc Example {} {
................................................................................

proc NewUnorderedList {} {
    # Itemized list - unordered list - bullet
    # 1. Base context provides indentation.
    # 2. First paragraph in a list item.
    # 3. All other paragraphs.
    ContextPush

    set base [ContextNew Itemized {
	MarginIn
	set bullet [IBullet]
    }] ; # {}

    set first [ContextNew First {
	List! bullet $bullet [BlankMargin]
................................................................................

# # ## ### ##### ########
##

proc OUL {f n} {
    CAttrSet _first $f
    CAttrSet _next  $n
    CAttrSet pcount 0
}

proc TD {t d} {
    CAttrSet _term       $t
    CAttrSet _definition $d
}

proc IsPara   {} { CAttrHas pcount }
proc Paras    {} { CAttrGet pcount }
proc PAdvance {} { CAttrIncr pcount 1 }



proc PReset   {} { CAttrSet pcount 0 }




















proc First    {} { CAttrGet _first }
proc Other    {} { CAttrGet _next }
proc Term     {} { CAttrGet _term }
proc Def      {} { CAttrGet _definition }
proc IsDef    {} { CAttrHas _definition }

# # ## ### ##### ########
##

proc CloseCurrent {{op PAdvance}} {
    if {[IsDef]} {

	# Currently in a definition list.
	CloseParagraph [Def]
    } elseif {[IsPara]} {

	# Currently in an (un)ordered list.

	if {![Paras]} {
	    # No paragraphs yet, this is first in the item
	    if {[CloseParagraph [First]]} $op
	} else {
	    # More paragraphs in the item
	    if {[CloseParagraph [Other]]} $op
	}
    } else {

	# Currently in a regular paragraph
	CloseParagraph
    }
}

proc GetCurrent {{op PAdvance}} {
    if {[IsDef]} {

	# Currently in a definition list.
	return [Def]
    } elseif {[IsPara]} {

	# Currently in an (un)ordered list.

	if {![Paras]} {
	    set res [First]
	} else {
	    set res [Other]
	}
	$op

	return $res
    } else {

	# Currently in a regular paragraph
	return {}
    }
}

# # ## ### ##### ########
##
................................................................................
c_pass 1 fmt_section     {name {id {}}} NOP
c_pass 2 fmt_section     {name {id {}}} {CloseParagraph ; Section $name ; return}

c_pass 1 fmt_subsection  {name {id {}}} NOP
c_pass 2 fmt_subsection  {name {id {}}} {CloseParagraph ; Subsection $name ; return}

c_pass 1 fmt_para {} NOP
c_pass 2 fmt_para {} {CloseCurrent ; return}





# NL is an alias of PARA
# See also fmt_example_begin
c_pass 1 fmt_nl {} NOP
c_pass 2 fmt_nl {} {CloseCurrent ; return }

c_pass 2 fmt_require {pkg {version {}}} NOP
................................................................................
}

# # ## ### ##### ########
##

c_pass 1 fmt_list_begin {what {hint {}}} NOP
c_pass 2 fmt_list_begin {what {hint {}}} {
    #puts_stderr "<<fmt_list_begin $what>>"

    CloseCurrent

    ContextPush
    NewList $what
    Off


    #puts_stderr "<<fmt_list_begin _____>>"

    return
}

c_pass 1 fmt_list_end {} NOP
c_pass 2 fmt_list_end {} {


    #puts_stderr "<<fmt_list_end>>"

    CloseCurrent
    ContextPop


    #puts_stderr "<<fmt_list_end ____>>"
    return
}

c_pass 1 fmt_lst_item {text} NOP
c_pass 2 fmt_lst_item {text} {
    #puts_stderr "<<fmt_lst_item \{$text\}>>"

    if {[IsOff]} { On } else { CloseParagraph [Def] }

    Text $text
    CloseParagraph [Term]

    #puts_stderr "<<fmt_lst_item _____>>"
    return
}

c_pass 1 fmt_bullet {} NOP
c_pass 2 fmt_bullet {} {
    if {[IsOff]} {On ; return}


    CloseCurrent PReset
    return
}

c_pass 1 fmt_enum {} NOP
c_pass 2 fmt_enum {} {
    if {[IsOff]} {On ; return}


    CloseCurrent PReset
    return
}

c_pass 1 fmt_cmd_def  {command} NOP
c_pass 2 fmt_cmd_def  {command} {fmt_lst_item [fmt_cmd $command]}

c_pass 1 fmt_arg_def {type name {mode {}}} NOP
................................................................................
    fmt_lst_item $text
}

# # ## ### ##### ########
##

c_pass 1 fmt_example_begin {} NOP
c_pass 2 fmt_example_begin {} { CloseCurrent ; return }








c_pass 1 fmt_example_end {} NOP
c_pass 2 fmt_example_end {} {

    TextTrimLeadingSpace
    
    set penv [GetCurrent]
    if {$penv != {}} {
	# In a list we save the current list context, activate the
	# proper paragraph context and create its example
	# variant. After closing the paragraph using the example we
	# restore and reactivate the list context.
	ContextPush
	ContextSet $penv

	CloseParagraph [Example]
	ContextPop
    } else {
	# In a regular paragraph we simple close the example

	CloseParagraph [Example]
    }


    return
}

c_pass 1 fmt_example {code} NOP
c_pass 2 fmt_example {code} {
    fmt_example_begin
    fmt_plain_text $code






|







 







>







 







<







|
|
|
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>









|

>



>

>


|


|


>





|

>



>

>





<
>


>







 







|
>
>
>
>







 







|

|
>
|
|

>

<
>





>
>
|

<
|
>

|





|

|
>



|





|
>
>
|





|
>
>
|







 







|
>
>
>
>
>
>
>



>










>




>


>
>







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
..
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
...
136
137
138
139
140
141
142

143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222

223
224
225
226
227
228
229
230
231
232
233
...
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
...
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360

361
362
363
364
365
366
367
368
369
370

371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
...
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
# # ## ### ##### ########
## Special manpage contexts

# example     = if present, context is for an example
# exenv       = if present, reference to example variant of current context

proc Example!  {} { CAttrSet example . }
proc Example?  {} { CAttrHas example }

proc NewExample {} {
    return [ContextNew Example { VerbatimOn ; Example! ; Prefix! "| " }] ; # {}
}

proc Example {} {
................................................................................

proc NewUnorderedList {} {
    # Itemized list - unordered list - bullet
    # 1. Base context provides indentation.
    # 2. First paragraph in a list item.
    # 3. All other paragraphs.
    ContextPush

    set base [ContextNew Itemized {
	MarginIn
	set bullet [IBullet]
    }] ; # {}

    set first [ContextNew First {
	List! bullet $bullet [BlankMargin]
................................................................................

# # ## ### ##### ########
##

proc OUL {f n} {
    CAttrSet _first $f
    CAttrSet _next  $n

}

proc TD {t d} {
    CAttrSet _term       $t
    CAttrSet _definition $d
}

proc IsPara   {} { CAttrHas _next }
proc Paras    {} { global __pcount ; set  __pcount }
proc PAdvance {} {
    global __pcount ; incr __pcount 1
    #puts_stderr "    ZZZ/ItemParas/Advance:$__pcount"
}
proc PReset   {} {
    #puts_stderr "    ZZZ/ItemParas/Reset"
    global __pcount ; set  __pcount 0 }

global __pcount  ; set __pcount  0
global __pcstack ; set __pcstack {}

proc PSave {} {
    global __pcount __pcstack
    lappend __pcstack $__pcount
    PReset
}

proc PRestore {} {
    global __pcount __pcstack
    set __pcount  [lindex $__pcstack end]
    set __pcstack [lrange $__pcstack 0 end-1]
    #puts_stderr "    ZZZ/ItemParas/Restore:$__pcount"
    return
}

proc First    {} { CAttrGet _first }
proc Other    {} { CAttrGet _next }
proc Term     {} { CAttrGet _term }
proc Def      {} { CAttrGet _definition }
proc IsDef    {} { CAttrHas _definition }

# # ## ### ##### ########
##

proc CloseCurrent {} {
    if {[IsDef]} {
	#puts_stderr "    ZZZ/CloseCurrent/Definitions"
	# Currently in a definition list.
	CloseParagraph [Def]
    } elseif {[IsPara]} {
	#puts_stderr "    ZZZ/CloseCurrent/UOL"
	# Currently in an (un)ordered list.
	#puts_stderr "    ZZZ/ItemParas/[Paras]"
	if {![Paras]} {
	    # No paragraphs yet, this is first in the item
	    if {[CloseParagraph [First]]} PAdvance
	} else {
	    # More paragraphs in the item
	    if {[CloseParagraph [Other]]} PAdvance
	}
    } else {
	#puts_stderr "    ZZZ/CloseCurrent/Plain"
	# Currently in a regular paragraph
	CloseParagraph
    }
}

proc GetCurrent {} {
    if {[IsDef]} {
	#puts_stderr "    ZZZ/GetCurrent/Definitions"
	# Currently in a definition list.
	return [Def]
    } elseif {[IsPara]} {
	#puts_stderr "    ZZZ/GetCurrent/UOL"
	# Currently in an (un)ordered list.
	#puts_stderr "    ZZZ/ItemParas/[Paras]"
	if {![Paras]} {
	    set res [First]
	} else {
	    set res [Other]
	}

	PAdvance
	return $res
    } else {
	#puts_stderr "    ZZZ/GetCurrent/Plain"
	# Currently in a regular paragraph
	return {}
    }
}

# # ## ### ##### ########
##
................................................................................
c_pass 1 fmt_section     {name {id {}}} NOP
c_pass 2 fmt_section     {name {id {}}} {CloseParagraph ; Section $name ; return}

c_pass 1 fmt_subsection  {name {id {}}} NOP
c_pass 2 fmt_subsection  {name {id {}}} {CloseParagraph ; Subsection $name ; return}

c_pass 1 fmt_para {} NOP
c_pass 2 fmt_para {} {
    CloseCurrent
    #puts_stderr "AAA/fmt_para/START"
    return
}

# NL is an alias of PARA
# See also fmt_example_begin
c_pass 1 fmt_nl {} NOP
c_pass 2 fmt_nl {} {CloseCurrent ; return }

c_pass 2 fmt_require {pkg {version {}}} NOP
................................................................................
}

# # ## ### ##### ########
##

c_pass 1 fmt_list_begin {what {hint {}}} NOP
c_pass 2 fmt_list_begin {what {hint {}}} {
    CloseCurrent

    #puts_stderr "AAA/fmt_list_begin/Setup $what"

    ContextPush ;# push outer
    NewList $what ;# base/controller of current/new/inner
    Off
    PSave


    #puts_stderr "AAA/fmt_list_begin/Enter"
    return
}

c_pass 1 fmt_list_end {} NOP
c_pass 2 fmt_list_end {} {
    CloseCurrent

    #puts_stderr "AAA/fmt_list_end/Exit"


    ContextPop ;# return to outer
    PRestore

    #puts_stderr "AAA/fmt_list_end/Done"
    return
}

c_pass 1 fmt_lst_item {text} NOP
c_pass 2 fmt_lst_item {text} {
    if {[IsOff]} { On } else { CloseParagraph [Def] }

    #puts_stderr "AAA/fmt_lst_item/(($text))"

    Text $text
    CloseParagraph [Term]

    #puts_stderr "AAA/fmt_lst_item/Done"
    return
}

c_pass 1 fmt_bullet {} NOP
c_pass 2 fmt_bullet {} {
    if {[IsOff]} { On } else { CloseCurrent }

    #puts_stderr "AAA/fmt_bullet/START"
    PReset
    return
}

c_pass 1 fmt_enum {} NOP
c_pass 2 fmt_enum {} {
    if {[IsOff]} { On } else { CloseCurrent }

    #puts_stderr "AAA/fmt_enum/START"
    PReset
    return
}

c_pass 1 fmt_cmd_def  {command} NOP
c_pass 2 fmt_cmd_def  {command} {fmt_lst_item [fmt_cmd $command]}

c_pass 1 fmt_arg_def {type name {mode {}}} NOP
................................................................................
    fmt_lst_item $text
}

# # ## ### ##### ########
##

c_pass 1 fmt_example_begin {} NOP
c_pass 2 fmt_example_begin {} {
    #puts_stderr "AAA/fmt_example_begin"

    CloseCurrent

    #puts_stderr "AAA/fmt_example_begin/Done"
    return
}

c_pass 1 fmt_example_end {} NOP
c_pass 2 fmt_example_end {} {
    #puts_stderr "AAA/fmt_example_end"
    TextTrimLeadingSpace
    
    set penv [GetCurrent]
    if {$penv != {}} {
	# In a list we save the current list context, activate the
	# proper paragraph context and create its example
	# variant. After closing the paragraph using the example we
	# restore and reactivate the list context.
	ContextPush
	ContextSet $penv
	#if {[CloseParagraph [Example]]} PAdvance
	CloseParagraph [Example]
	ContextPop
    } else {
	# In a regular paragraph we simple close the example
	#if {[CloseParagraph [Example]]} PAdvance
	CloseParagraph [Example]
    }

    #puts_stderr "AAA/fmt_example_end/Done"
    return
}

c_pass 1 fmt_example {code} NOP
c_pass 2 fmt_example {code} {
    fmt_example_begin
    fmt_plain_text $code