Tcl Library Source Code

Check-in [0f2ecff317]
Login

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

Overview
Comment:Started generation of markdown: docidx.
Timelines: family | ancestors | descendants | both | doc-fixup-and-markdown
Files: files | file ages | folders
SHA3-256:0f2ecff3171a6ce9ea9f6117c01783d126a6a7ca9d3d94d88b53073f3f9a209b
User & Date: aku 2019-03-15 06:28:37
Context
2019-03-18
19:57
Continued generation of markdown: doctoc. check-in: 61b61eed41 user: aku tags: doc-fixup-and-markdown
2019-03-15
06:28
Started generation of markdown: docidx. check-in: 0f2ecff317 user: aku tags: doc-fixup-and-markdown
2019-03-14
19:35
Shuffled the test support files for doctools around for a nicer hierarchy, with fmt, idx, and toc properly segregated. Updated the test suite to match the changes. Furthermore dropped superfluous checks for long-gone `CVS` directories. check-in: 7e7f01191f user: aku tags: doc-fixup-and-markdown
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to modules/doctools/docidx.test.

308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323

# -------------------------------------------------------------------------
## Series of tests for all available backends, check their formatting.

set k 11
foreach format {
    html nroff text
    wiki null
} {
    set n 0
    foreach src [TestFilesGlob tests/idx/idx/*] {
	# Get the expected result
	set dst [localPath [file join tests idx $format [file tail $src]]]
	set map {} ; lappend map @[email protected] $tcl_platform(user)
	set rem {} ; lappend rem $tcl_platform(user) @[email protected]






|
|







308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323

# -------------------------------------------------------------------------
## Series of tests for all available backends, check their formatting.

set k 11
foreach format {
    null html nroff
    text wiki markdown
} {
    set n 0
    foreach src [TestFilesGlob tests/idx/idx/*] {
	# Get the expected result
	set dst [localPath [file join tests idx $format [file tail $src]]]
	set map {} ; lappend map @[email protected] $tcl_platform(user)
	set rem {} ; lappend rem $tcl_platform(user) @[email protected]

Added modules/doctools/mpformats/_markdown.tcl.












































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# -*- tcl -*-
#
# -- Core support for markdown
#
# Copyright (c) 2019 Andreas Kupries <[email protected]>
# Freely redistributable.

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

# # ## ### ##### ########
## `markdown` formatting

proc SectTitle {lb title} {
    upvar 1 $lb lines
    lappend lines "# $title"
    return
}

proc SubsectTitle {lb title} {
    upvar 1 $lb lines
    lappend lines "## $title"
    return
}

proc Sub3Title {lb title} {
    upvar 1 $lb lines
    lappend lines "### $title"
    return
}

proc Sub4Title {lb title} {
    upvar 1 $lb lines
    lappend lines "#### $title"
    return
}

proc Strong {text} { return __${text}__ }
proc Em     {text} { return *${text}* }

Added modules/doctools/mpformats/idx.markdown.






























































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
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
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
234
235
236
237
238
239
# -*- tcl -*-
# Engine to convert a docidx document into markdown text.
#
# Copyright (c) 2019 Andreas Kupries <[email protected]>
# Freely redistributable.
#
######################################################################

dt_source _idx_common.tcl
dt_source _text.tcl
dt_source _markdown.tcl

proc c_copyrightsymbol {} {return "(c)"}

######################################################################
# Conversion specification.
# One-pass processing.

rename idx_postprocess {}
rename text_postprocess idx_postprocess
proc   fmt_plain_text {text} {return {}}

################################################################
## Backend for plain text markup

proc fmt_index_begin {label title} {
    if {($label != {}) && ($title != {})} {
	set title "$label -- $title"
    } elseif {$label != {}} {
	set title $label
    } elseif {$title != {}} {
	 # title is set
    }

    TextInitialize

    Text "\[//\]: # (Index [Provenance])"
    CloseParagraph [Verbatim]

    SectTitle hdr $title
    Text [Compose hdr]
    CloseParagraph [Verbatim]
    return
}

proc fmt_index_end {} {
    LoadKwid
    NavBar
    Keys
    return
    
    set rmargin [RMargin $max]

    incr max
    set blank [Blank $max] ;# indent

    foreach key [lsort [array names map]] {
	set keys [join $map($key) ", "]
	Text [InFlow $keys $rmargin [ReHead $blank $key] $blank]
	CloseParagraph [Verbatim]
    }
    return
}

proc fmt_key {text} {
    global key lk ch
    set lk $text
    set key($lk) {}
    set ch([F $lk]) .
    return
}

proc fmt_manpage {f l} {Ref [dt_fmap $f] $l}
proc fmt_url     {u l} {Ref $u           $l}
proc fmt_comment {text}       {return}

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

proc NavBar {} {
    global ch dot
    if {![array size ch]} return
    
    set nav {}
    foreach c [lsort -dict [array names ch]] {
	set ref c[F $c]
	set ch($c) $ref
	lappend nav [ALink #$ref $c]
    }

    Separator
    
    Text [join $nav $dot]
    CloseParagraph [Verbatim]

    Separator
    return
}

proc Keys {} {
    global key
    set lc {}
    set kwlist {}

    # For a good display we sort keywords in dictionary order.
    # We ignore their leading non-alphanumeric characters.
    set kwlist {}
    foreach kw [array names key] {
       set kwx [string trim [regsub -all {^[^a-zA-Z0-9]+} $kw {}]]
       lappend kwlist [list $kwx $kw]
    }
    foreach item [lsort -index 0 -dict $kwlist] {
       foreach {_ k} $item break
	set c [F $k]
	if {$lc != $c} {
	    CloseParagraph [Verbatim]
	    Section $c ; set lc $c
	}
	BeginKey   $k
	References $k
	EndKey
    }

    CloseParagraph [Verbatim]
    return

}

proc Section {c} {
    global ch
    Text "#### [SetAnchor "Keywords: $c" $ch($c)]"
    CloseParagraph [Verbatim]

    Text "|||\n"
    Text "|---|---|\n"
    return
}

proc BeginKey {k} {
    Text "|[SetAnchor $k]|"
}

proc References {k} {
    global key dot
    set refs {}
    foreach {ref label} $key($k) {
	lappend refs [SetAnchor $label $ref]
    }
    Text [join $refs $dot]
    return
}

proc EndKey {} {
    Text "|\n"
}

proc Separator {} {
    Text ----
    CloseParagraph [Verbatim]
}

proc ALink {dst label} { return "\[$label]($dst)" }

proc SetAnchor {text {name {}}} {
    if {$name == {}} { set name [Anchor $text] }
    return "<a name='$name'></a>$text"
}

proc Anchor {text} {
    global kwid
    if {[info exists kwid($text)]} {
	return "$kwid($text)"
    }
    return [A $text]
}

proc A {text} {
    set anchor [regsub -all {[^a-zA-Z0-9]} [string tolower $text] {_}]
    set anchor [regsub -all {__+} $anchor _]
    return $anchor
}

# ### ### ### ######### ######### #########
## Engine state

proc LoadKwid {} {
    global kwid
    # Engine parameter - load predefined keyword anchors.
    set             ki [Get kwid]
    if {![llength  $ki]} return
    array set kwid $ki
    return
}

proc Ref {r l} {
    global  key  lk
    lappend key($lk) $r $l
    return
}

proc F {text} {
    # Keep only alphanumeric, take first, uppercase
    # Returns nothing if input has no alphanumeric characters.
    return [string toupper [string index [regsub -all {[^a-zA-Z0-9]} $text {}] 0]]
}

# key  : string -> dict(ref -> label) "key formatting"
# ch   : string -> '.'                "key starting characters"
# lk   : string                       "last key"
# kwid : string -> ...
# even : bool

global key  ; array set key  {}
global ch   ; array set ch   {}
global lk   ; set       lk   {}
global la   ; set       la   {}
global ti   ; set       ti   {}
global kwid ; array set kwid {}
global dot  ; set dot   { &#183; }

# ### ### ### ######### ######### #########
## Engine parameters

global    __var
array set __var {
    kwid {}
}
proc Get               {varname}      {global __var ; return $__var($varname)}
proc idx_listvariables {}             {global __var ; return [array names __var]}
proc idx_varset        {varname text} {
    global __var
    if {![info exists __var($varname)]} {
	return -code error "Unknown engine variable \"$varname\""
    }
    set __var($varname) $text
    return
}

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

Added modules/doctools/tests/idx/markdown/00.








>
>
>
>
1
2
3
4
[//]: # (Index generated by tcllib/doctools/idx with format 'markdown')

# KWIC -- Test

Added modules/doctools/tests/idx/markdown/01.
































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[//]: # (Index generated by tcllib/doctools/idx with format 'markdown')

# KWIC -- Test

----

[L](#cL)

----

#### <a name='cL'></a>Keywords: L

|||
|---|---|
|<a name='lorem'></a>lorem|<a name='ipsum'></a>dolores|

Added modules/doctools/tests/idx/markdown/02.














































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[//]: # (Index generated by tcllib/doctools/idx with format 'markdown')

# KWIC -- Test

----

[D](#cD) &#183; [L](#cL)

----

#### <a name='cD'></a>Keywords: D

|||
|---|---|
|<a name='dolores'></a>dolores|<a name='lorem'></a>ipsum &#183; <a name='dolores'></a>lorem &#183; <a name='ipsum'></a>dolores|


#### <a name='cL'></a>Keywords: L

|||
|---|---|
|<a name='lorem'></a>lorem|<a name='ipsum'></a>dolores &#183; <a name='lorem'></a>ipsum|