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
|
# -*- tcl -*-
#
# $Id: idx.html,v 1.7 2005/09/28 04:51:19 andreas_kupries Exp $
#
# Engine to convert a docidx document into HTML.
#
# Copyright (c) 2003 Andreas Kupries <andreas_kupries@sourceforge.net>
# Freely redistributable.
#
######################################################################
dt_source _idx_common.tcl
dt_source _html.tcl
######################################################################
# Conversion specification.
#
# One-pass processing.
rename idx_postprocess {}
rename fmt_postprocess idx_postprocess
proc fmt_plain_text {text} {return {}}
################################################################
## Backend for HTML markup
global firstkey ; set firstkey 1
global even ; set even 1
global reflist ; set reflist [list]
global cnt ; set cnt 0
global kwid
array set kwid {}
proc fmt_index_begin {label title} {
set hdr ""
append hdr "[markup <html><head>]\n"
append hdr "[markup <title>] $label [markup </title>]\n"
# Engine parameter - insert 'meta'
if {[set meta [Get meta]] != {}} {append hdr [markup $meta]\n}
# Engine parameter - load predefined keyword anchors.
if {[llength [set ki [Get kwid]]]} {
global kwid
array set kwid $ki
}
append hdr "[markup </head>]\n"
append hdr [ht_comment [c_provenance]]\n
append hdr [ht_comment "CVS: \$Id\$ $label"]\n
append hdr \n
append hdr [markup <body>]\n
# Engine parameter - insert 'header'
if {[set header [Get header]] != {}} {append hdr [markup $header]\n}
if {($label != {}) && ($title != {})} {
append hdr "[markup <h3>] $label -- $title [markup </h3>]\n"
} elseif {$label != {}} {
append hdr "[markup <h3>] $label [markup </h3>]\n"
} elseif {$title != {}} {
append hdr "[markup <h3>] $title [markup </h3>]\n"
}
append hdr [markup "<hr><table class=\"#idx\">"]\n
return $hdr
}
proc fmt_index_end {} {
set text [FlushReferences]
append text [tag/ table]\n
# Engine parameter - insert 'footer'
set footer [Get footer]
if {$footer != {}} {set footer \n[markup $footer]\n}
return $text[tag hr]${footer}[tag/ body][tag/ html]\n
}
proc fmt_key {text} {
global firstkey even reflist cnt kwid
set res [FlushReferences]
set firstkey 0
if {$even} {
append res [markup "<tr class=\"#idxeven\" valign=top>"]\n
} else {
append res [markup "<tr class=\"#idxodd\" valign=top>"]\n
}
set even [expr {1-$even}]
if {[info exists kwid($text)]} {
set anchor $kwid($text)
} else {
set anchor key$cnt
incr cnt
}
append res " [markup {<td class="#idxleft" >}]"
append res "[markup "<a name=\"$anchor\">"] ${text} [markup </a>][tag/ td]\n"
append res " [markup {<td class="#idxright">}]\n"
return $res
}
proc FlushReferences {} {
global firstkey reflist
set res ""
if {!$firstkey} {
set lines [list]
foreach {ref label} $reflist {
lappend lines "\t[markup "<a href=\"$ref\">"] ${label} [tag/ a]"
}
append res "[join $lines ,\n]\n [tag /td]\n[tag/ tr]\n"
}
set reflist [list]
return $res
}
proc fmt_manpage {file label} {global reflist ; lappend reflist [dt_fmap $file] $label ; return}
proc fmt_url {url label} {global reflist ; lappend reflist $url $label ; return}
proc fmt_comment {text} {ht_comment $text}
################################################################
global __var
array set __var {
meta {}
header {}
footer {}
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
}
################################################################
|