# -*- tcl -*-
#
# fmt.html
#
# Copyright (c) 2001-2003 Andreas Kupries
#
# [expand] definitions to convert a tcl based manpage definition into
# a manpage based upon HTML markup. Additional definition files allow
# the conversion into nroff and TMML.
#
################################################################
################################################################
dt_source _common.tcl ; # Shared code
dt_source _html.tcl ; # HTML basic formatting
proc bgcolor {} {return ""}
proc border {} {return 0}
proc Year {} {clock format [clock seconds] -format %Y}
# possibleReference text gi --
# Check if $text is a potential cross-reference;
# if so, format as a reference;
# otherwise format as a $gi element.
#
proc c_possibleReference {text gi} {
global SectionNames
if {[info exists SectionNames($text)]} {
return [taga a [list href #$SectionNames($text)]]$text[tag/ a]
} else {
return [tag $gi]$text[tag/ $gi]
}
}
c_holdBuffers require
################################################################
## Backend for HTML markup
# --------------------------------------------------------------
# Handling of lists. Simplified, the global check of nesting and
# legality of list commands allows us to throw away most of the
# existing checks.
global liststack ; # stack of list tags to use in list_end
global hintstack ; # stack of hint information.
global chint ; # current hint settings
global lmark ; # boolean flag, 1 = list item command was last
# ; # 0 = something other than a list item command
set liststack [list]
set hintstack [list]
set chint ""
set lmark 0
proc llevel {} {global liststack ; return [llength $liststack]}
proc lpush {t hint} {
global liststack hintstack chint
lappend liststack [tag/ $t]
lappend hintstack $chint
set chint $hint
return [tag $t]
}
proc lpop {} {
global liststack hintstack chint
set t [lindex $liststack end]
set liststack [lreplace $liststack end end]
set chint [lindex $hintstack end]
set hintstack [lreplace $hintstack end end]
return $t
}
proc lsmark {value} {
global lmark ; set lmark $value ; return
}
proc limark {} {
# hint and mark processing.
# hint: compact list, do not create additional whitespace
if {[lcompact]} {return ""}
# hint: wide list, create additional whitespace.
# mark: exception: two list items following each other have no whitespace.
global lmark ; if {$lmark} {return ""}
return [tag br][tag br]\n
}
proc lcompact {} {global chint ; string equal $chint compact}
proc fmt_plain_text {text} {
# Control list state
set redux [string map [list " " "" "\t" "" "\n" ""] $text]
if {$redux != {}} {lsmark 0}
return $text
}
################################################################
# Formatting commands.
c_pass 1 fmt_manpage_begin {title section version} {c_cinit ; return}
c_pass 2 fmt_manpage_begin {title section version} {
c_cinit
set module [dt_module]
set shortdesc [c_get_module]
set description [c_get_title]
set copyright [c_get_copyright]
set hdr ""
append hdr "[markup ]$title - $shortdesc [markup ]\n"
append hdr [ht_comment [c_provenance]]\n
if {$copyright != {}} {
append hdr [ht_comment $copyright]\n
}
append hdr [ht_comment "CVS: \$Id\$ $title.$section"]\n
append hdr \n
append hdr "[markup ] [string trimleft $title :]($section) $version $module \"$shortdesc\"[markup
]\n"
append hdr [fmt_section NAME]\n
append hdr "[fmt_para] $title - $description"
return $hdr
}
c_pass 1 fmt_moddesc {desc} {c_set_module $desc}
c_pass 2 fmt_moddesc {desc} NOP
c_pass 1 fmt_titledesc {desc} {c_set_title $desc}
c_pass 2 fmt_titledesc {desc} NOP
c_pass 1 fmt_copyright {desc} {c_set_copyright $desc}
c_pass 2 fmt_copyright {desc} NOP
c_pass 1 fmt_manpage_end {} {c_creset ; return}
c_pass 2 fmt_manpage_end {} {
c_creset
set res ""
set copyright [c_get_copyright]
if {$copyright != {}} {
append res [fmt_section COPYRIGHT] \n
append res [join [split $copyright \n] [tag br]\n] [tag br]\n
}
append res [markup