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
|
# RCS: @(#) $Id: html.tcl,v 1.3 2002/07/10 10:57:39 barras Exp $
# Copyright (C) 2000, DGA - part of the Transcriber program
# distributed under the GNU General Public License (see COPYING file)
################################################################
namespace eval html {
variable msg "HTML format"
variable ext ".html"
proc quote val {
regsub -all "&" $val {\&} val
regsub -all "<" $val {\<} val
regsub -all ">" $val {\>} val
return $val
}
proc export {name} {
global v
set channel [open $name w]
if {![catch {encoding system}]} {
fconfigure $channel -encoding [EncodingFromName $v(encoding)]
}
set episode [$v(trans,root) getChilds "element" "Episode"]
set bg ""
set basename [quote [file root [file tail $v(sig,name)]]]
puts $channel "<?xml version='1.0' encoding='UTF-8' ?>\n<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
\"http://www.w3.org/TR/html4/loose.dtd\">\n<html>\n<head>\n<title>$basename</title>\n"
if {![catch {encoding system}]} {
puts $channel "<meta http-equiv=\"ContentType\" content=\"text/html; charset=$v(encoding)\">"
}
puts $channel "</head>\n<body>"
puts $channel "<center><h1>$basename</h1></center>"
puts $channel [quote "Program [$episode getAttr program]"]
puts $channel [quote "of [$episode getAttr air_date]"]
puts $channel "<br>"
puts $channel [quote "Transcribed by [$v(trans,root) getAttr scribe],"]
puts $channel [quote "version [$v(trans,root) getAttr version]"]
puts $channel [quote "of [$v(trans,root) getAttr version_date]"]
foreach sec [$episode getChilds "element" "Section"] {
set topic [::section::long_name $sec]
puts $channel "<center><h2><font color=\"\#995000\">[quote $topic]</font></h2></center>"
set turns [$sec getChilds "element" "Turn"]
for {set nt 0} {$nt < [llength $turns]} {incr nt} {
set tur [lindex $turns $nt]
set spk [::turn::get_name $tur]
puts $channel "<h3><font color=\"\#3366FF\">[quote $spk]</font></h3>"
puts $channel "<ul>"
set li 0
foreach chn [$tur getChilds] {
if {[$chn class] == "data"} {
set text [$chn getData]
if {$text != ""} {
puts $channel [quote $text]
}
} elseif {[$chn class] == "element"} {
switch [$chn getType] {
"Sync" {
if {$li} {
puts $channel "</li>"
}
puts $channel "<li>"
set li 1
}
"Background" {
if {$bg != ""} {
puts $channel " <b>\[-$bg]</b> "
}
set bgTyp [$chn getAttr "type"]
set bgLvl [$chn getAttr "level"]
if {$bgLvl != "off"} {
set bg $bgTyp
puts $channel " <b>\[$bg-]</b> "
} else {
set bg ""
}
}
"Who" {
set nb [$chn getAttr "nb"]
if {$nb > 1} {
puts $channel "<br>"
}
puts $channel "<b>$nb:</b> "
}
"Event" - "Comment" {
puts $channel "<i>[quote [StringOfEvent $chn]]</i>"
}
}
}
}
if {$li} {
puts $channel "</li>"
}
puts $channel "</ul>"
}
}
puts $channel "</body>\n</html>"
close $channel
# Launch browser on exported .html
set url $name
if {[catch {
exec iexplore $url &
}] && [catch {
exec netscape -remote "openFile ($url)"
}] && [catch {
exec netscape $url &
}]} {
}
}
}
|