--- ../../../wikitcl-preview_edit_help/wikit/format.tcl	2008-04-03 01:58:06.000000000 -0500
+++ format.tcl	2008-04-05 23:28:38.000000000 -0500
@@ -5,7 +5,7 @@
 
 namespace eval Wikit::Format {
   namespace export TextToStream StreamToTk StreamToTcl StreamToHTML StreamToRefs \
-    StreamToUrls Expand_HTML FormatWikiToc ShowDiffs
+    StreamToUrls Expand_HTML
 
   # In this file:
   #
@@ -115,6 +115,20 @@
     set optlen 0	 	  ; # length of option block fixed part
     foreach line [split $text \n] {
       # Per line, classify the it and extract the main textual information.
+
+      # Patches from SteveR/SRIV
+      ## Comment in the Wiki Text
+      if {[string match "### *" $line]} {
+        continue
+      }
+
+      # Include another Wiki page in this Wiki page
+      if {[regexp {^\[@include (.*)\]$} [string trim $line] - arg]} {
+        eval lappend irep [IncludeStream $arg]
+        continue
+      }
+      # End patches from SteveR/SRIV
+
       foreach {tag depth txt aux} [linetype $line] break ; # lassign
       set otag $tag
       if {$mode_fixed && $tag ne "FIXED" && $tag ne "CODE" \
@@ -151,7 +165,7 @@
       ## there is any.
       #
       switch -exact -- $tag {
-        HR - 1UL - 2UL - 3UL - 4UL - 5UL - 1OL - 2OL - 3OL - 4OL - 5OL - DL - PRE - TBL - CTBL - TBLH - HD2 - HD3 - HD4 - BLAME_START - BLAME_END - CENTERED - BACKREFS {
+        HR - 1UL - 2UL - 3UL - 4UL - 5UL - 1OL - 2OL - 3OL - 4OL - 5OL - DL - PRE - TBL - CTBL - TBLH - HD2 - HD3 - HD4 - CENTERED {
           if {$paragraph != {}} {
             if {$mode_fixed} {
               lappend irep FI {}
@@ -280,35 +294,7 @@
           set paragraph {}
         }
         FIXED_CONTENT {
-          if { $otag eq "BLAME_START" } {
-            if {$paragraph ne {}} {
-              set paragraph [join $paragraph \n]
-              lappend irep FI {}
-              if {$mode_code} {
-                lappend irep {} $paragraph
-              } else {
-                render $paragraph
-              }
-              lappend irep FE {}
-            }
-            set paragraph {}
-            lappend irep BLS [string range $line 6 end]
-          } elseif { $otag eq "BLAME_END" } { 
-            if {$paragraph ne {}} {
-              set paragraph [join $paragraph \n]
-              lappend irep FI {}
-              if {$mode_code} {
-                lappend irep {} $paragraph
-              } else {
-                render $paragraph
-              }
-              lappend irep FE {}
-            }
-            set paragraph {}
-            lappend irep BLE 0
-          } else {
-            lappend paragraph $txt
-          }
+          lappend paragraph $txt
         }
         OPTION {
           if {$mode_option} {
@@ -333,45 +319,21 @@
           }
         }
         OPTION_CONTENT {
-          if { $otag eq "BLAME_START" || $otag eq "BLAME_END"} {
-            lappend irep L "$optnum $optlen"
-            set mode_option 0
-            set optlen 0
-            if { $otag eq "BLAME_START" } { 
-              lappend irep BLS [string range $line 6 end]
-            } else {
-              lappend irep BLE 0
-            }
-            # start new option list
-            if {$empty_std} {
-              lappend irep C 0 {} {}
-              set empty_std 0
-            }
-            if {$paragraph ne ""} {
-              lappend irep T 0
-              render $paragraph
-              set paragraph ""
-            }
-            set mode_option 1
-            set optlen 0
-            lappend irep L [incr optnum]
-          } else {
-            # the fixed part should be followed by one or more tabs
-            # - if not then fall back to using the first double-space
-            #   then the first space
-            if {[regexp {^\s*(.+?)\t\s*(.*)$} $txt - opt rest]
-                || [regexp {^\s*(.+?)\s{2,}(.*)$} $txt - opt rest]
-                || [regexp {^\s*(.+?)\s+(.*)$} $txt - opt rest]
-              } {
-              set opt [string trim $opt]
-              regsub -all \t $rest \s rest
-              lappend irep F 0
-              set optlen [max $optlen [render $opt]]
-              lappend irep V \t
-              render $rest V
-            } elseif {$txt eq ""} {
-              lappend irep F 0
-            }
+          # the fixed part should be followed by one or more tabs
+          # - if not then fall back to using the first double-space
+          #   then the first space
+          if {[regexp {^\s*(.+?)\t\s*(.*)$} $txt - opt rest]
+              || [regexp {^\s*(.+?)\s{2,}(.*)$} $txt - opt rest]
+              || [regexp {^\s*(.+?)\s+(.*)$} $txt - opt rest]
+            } {
+            set opt [string trim $opt]
+            regsub -all \t $rest \s rest
+            lappend irep F 0
+            set optlen [max $optlen [render $opt]]
+            lappend irep V \t
+            render $rest V
+          } elseif {$txt eq ""} {
+            lappend irep F 0
           }
         }
         EVAL {
@@ -458,18 +420,9 @@
             lappend irep TD 0 ; render $te ; lappend irep TDE 0
           }
         }
-        BLAME_START {
-          lappend irep BLS $txt
-        }
-        BLAME_END {
-          lappend irep BLE 0
-        }
         CENTERED {
           lappend irep CT 0
         }
-        BACKREFS {
-          lappend irep BACKREFS $txt
-        }
         default {
           error "Unknown linetype $tag"
         }
@@ -533,10 +486,7 @@
       CODE   {^()()(======)$}
       OPTION {^()()(\+\+\+)$}
       #EVAL {^(\+eval)(\s?)(.+)$}
-      BLAME_START {^(>>>>>>)(\s?)(.+)$}
-      BLAME_END   {^(<<<<<<)$}
       CENTERED {^()()(!!!!!!)$}
-      BACKREFS {^(<<backrefs>>)()(.*)$}
     } {
       # Compat: Remove restriction to multiples of 3 spaces.
       if {[regexp $re $line - pfx aux txt]} {
@@ -642,6 +592,7 @@
     set lre2 {\m(https?|ftp|news|mailto|file):([^\s:]\S*[^\]\)\s\.,!\?;:'>"]%\|%[^%]+%\|%)} ; # "
 
     set blre "\\\[\0\1u\2(\[^\0\]*)\0\\\]"
+    set bllre "\\\[\0\1u\2(\[^\0\]*)\0\\s\\|\\s(\[^\\]]\*)\\\]"
 
                                                  # Order of operation:
                                                  # - Remap double brackets to avoid their interference.
@@ -676,6 +627,12 @@
 
                                                  # External links in brackets are simpler cause we know where the
                                                  # links are already.
+                                                 ##sriv
+                                                 ### First handle external links with labels
+                                                 ###
+                                                 regsub -all $bllre $text "\0\1u\2\\1%|%\\2\0" text
+                                                 ### Now external links without labels.
+                                                 ##sriv
                                                  regsub -all $blre $text "\0\1x\2\\1\0" text
                                                  ## puts stderr D>>$text<<*
 
@@ -1046,12 +1003,6 @@
           lappend $cresult $vspace($state$mode) ""
           set state $mode
         }
-        BLS {
-          lappend $cresult $text body
-        }
-        BLE {
-          lappend $cresult $text body
-        }
         BR {
           lappend $cresult "\n" body
           set state T
@@ -1063,31 +1014,6 @@
         CT {
           lappend $cresult "\n" body
         }
-        BACKREFS {
-          if { $brp eq "" } {
-            if { [string length $text]} {
-              lappend $cresult "Back references to current page not available." body
-            } else {
-              lappend $cresult "Back references to '$text' not available." body
-            }
-          } else {
-            lappend $cresult "\n" body
-            if { [string length $text]} {
-              set refList [eval $brp [list $text]]
-            } else {
-              set refList [eval $brp $N]
-            }
-            
-            foreach br $refList {
-              lassign $br date name who from
-              set     n    [incr count]
-              lappend urls g $n $name
-              lappend $cresult "\n   \u2022 " body $name [list url g$n]
-            }
-            lappend $cresult "\n" body
-#            lappend $cresult $text body
-          }
-        }
       }
     }
     if {[llength $tresult]} {
@@ -1430,12 +1356,7 @@
   }
 
   proc StreamToHTML {s {cgi ""} {ip ""}} {
-
-    # here so we aren't dependent on cksum unless rendering to HTML
-    package require cksum
-
     set result ""
-    set tocpos {}
     set state H   ; # bogus hline as initial state.
     set vstate "" ; # Initial state of visual FSM
     set count 0
@@ -1444,31 +1365,19 @@
     set centered 0
     set trow 0
     set backrefid 0
-    set brefs {}
-    set in_header 0
-    set tocheader ""
 
     variable html_frag
 
     foreach {mode text} $s {
       switch -exact -- $mode {
         {}    {
-	  if { $in_header } {
-            append tocheader [quote $text]
-	  }
           append result [quote $text]
         }
         b - i - f {
-	  if { $in_header } {
-            append tocheader [quote $text]
-	  }
           append result $html_frag($mode$text)
         }
         g - G {
           lassign [split_url_link_text $text] link text
-	  if { $in_header } {
-            append tocheader [quote $text]
-	  }
           if {$cgi == ""} {
             append result "\[[quote $text]\]"
             continue
@@ -1497,7 +1406,7 @@
             if { $mode eq "G" } {
               append result $html_frag(A_) /_ref/$id
             } else {
-              append result $html_frag(a_) /$id
+              append result $html_frag(a_) $id
             }
             append result $html_frag(tc) \
               [quote $text] $html_frag(_a)
@@ -1511,25 +1420,19 @@
           } else {
             # use ID -- editor link on the brackets.
             append result \
-              $html_frag(a_) /$id $html_frag(tc) \[ $html_frag(_a) \
+              $html_frag(a_) $id $html_frag(tc) \[ $html_frag(_a) \
               [quote $text] \
-              $html_frag(a_) /$id $html_frag(tc) \] $html_frag(_a) \
+              $html_frag(a_) $id $html_frag(tc) \] $html_frag(_a) \
             }
           }
         u {
           lassign [split_url_link_text $text] link text
-	  if { $in_header } {
-	    append tocheader [quote $text]
-	  }
           append result \
             $html_frag(e_) [quote $link] $html_frag(tc) \
             [quote $text] $html_frag(_a)
         }
         x {
           lassign [split_url_link_text $text] link text
-	  if { $in_header } {
-	    append tocheader [quote $text]
-	  }
           if {[regexp -nocase {\.(gif|jpg|jpeg|png)$} $link]} {
             append result $html_frag(i_) $link $html_frag(tc)
           } else {
@@ -1544,71 +1447,23 @@
           append result $text
         }
         HD2 - HD3 - HD4 {
-          if {$mode eq "HD2"} {
-            append result "$html_frag($state$mode) id='pagetocXXXXXXXX'>" 
-          } else {
-            append result "$html_frag($state$mode)>" 
-          }
-          lappend tocpos [string index $mode 2] [string length $result]
+          append result "$html_frag($state$mode)>"
           set state $mode
-	  set in_header 1
-	  set tocheader ""
         }
         HDE {
-          lappend tocpos $tocheader
-	  set in_header 0
-        }
-        BLS {
-          append result $html_frag($state$mode)
-          foreach {bltype page version who when} [split $text ";"] break
-          switch -exact -- $bltype {
-            a {
-              append result "\n<div class='annotated'>\n"
-              append result "  <span class='versioninfo'>\n"
-              append result "    <span class='versionnum'><a href='[quote /_revision/$page?V=$version&A=1]'>$version</a></span>\n"
-              append result "    <span class='versionwho'>$who</span><br>\n"
-              append result "    <span class='versiondate'>$when</span>\n"
-              append result "  </span>\n"
-            }
-            n {
-              append result "<div class='newwikiline' id='diff$insdelcnt'>"
-              incr insdelcnt
-            }
-            o {
-              append result "<div class='oldwikiline' id='diff$insdelcnt'>"
-              incr insdelcnt
-            }
-            w {
-              append result "<div class='whitespacediff' id='diff$insdelcnt'>"
-              incr insdelcnt
-            }
-          }
-          set state $mode 
-        }
-        BLE {
-          append result $html_frag($state$mode)
-          switch -exact -- $bltype {
-            a {
-              append result "\n</div>\n"
-            }
-            w -
-            n -
-            o {
-              append result "</div>"
-            }
-          }
-          set state $mode 
         }
         TR - CTR - TD - TDE - TRH - TDH - TDEH - T - Q - I - D - 1U - 2U - 3U - 4U - 5U - 1O - 2O - 3O - 4O - 5O - H - FI - FE - L - F {
           if { $mode eq "CTR" } { 
             set mode TR
-            set oddoreven [expr {$trow % 2 ? "odd" : "even"}]
+            set oddoreven [expr {$trow % 2 ? "wikit_table_row_odd" : "wikit_table_row_even"}]
             incr trow
           } else {
-            set oddoreven ""
+            set oddoreven "wikit_table_row"
+          }
+          catch {
+            append result [subst $html_frag($state$mode)]
+            set state $mode
           }
-          append result [subst $html_frag($state$mode)]
-          set state $mode
         }
         BR {
           append result "<br>"
@@ -1628,20 +1483,6 @@
           }
           set state T
         }
-        BACKREFS {
-          set mode T
-          set text [string trim $text]
-          append result [subst $html_frag($state$mode)]
-          lappend brefs backrefs$backrefid $text
-          if { [string length $text]} {
-            set htext "<b>$text</b>"
-          } else {
-            set htext "current page"
-          }
-          append result "\n<div class='backrefs' id='backrefs$backrefid'>Fetching backrefs for <b>$htext</b>...</div>\n"
-          set state T
-          incr backrefid
-        }
       }
     }
     # Close off the last section.
@@ -1649,34 +1490,7 @@
       append result $html_frag(${state}_)
     }
 
-    # Create page-TOC
-    set toc ""
-    set toce ""
-    if { [llength $tocpos] } {
-      append toc "<div class='toc1'>Page contents\n"
-      foreach {ht tpb thdr} $tocpos {
-        if { $ht == 2 } {
-          set tkn [::crc::CksumInit]
-          ::crc::CksumUpdate $tkn $thdr
-          set cksum [::crc::CksumFinal $tkn]
-          if {[string length $toce]} {
-            append toc "<div class='toc2'>$toce</div>\n"
-            set toce ""
-          }
-          set toce "<a class='toc' href='#pagetoc[format %08x $cksum]'>[armour_quote $thdr]</a>"
-          set result [string replace $result [expr {$tpb-10}] [expr {$tpb-3}] [format %08x $cksum]]
-        }
-      }
-      if {[string length $toce]} {
-        append toc "<div class='toc3'>$toce</div>\n"
-      }
-      append toc "</div>"
-    }
-
-    # Get rid of spurious newline at start of each quoted area.
-    regsub -all "<pre>\n" $result "<pre>" result
-
-    list $result {} $toc $brefs
+    return [list $result]
   }
 
   proc quote {q} {
@@ -1724,8 +1538,6 @@
   vs HD2  T                 </h2><p> ;vs HD2  Q                 </h2><pre> ;vs HD2  U                 </h2><ul><li> ;vs HD2  O                 </h2><ol><li>
   vs HD3  T                 </h3><p> ;vs HD3  Q                 </h3><pre> ;vs HD3  U                 </h3><ul><li> ;vs HD3  O                 </h3><ol><li>
   vs HD4  T                 </h4><p> ;vs HD4  Q                 </h4><pre> ;vs HD4  U                 </h4><ul><li> ;vs HD4  O                 </h4><ol><li>
-  vs BLS  T                    <p>\n ;vs BLS  Q                    \n<pre> ;vs BLS  U                    \n<ul><li> ;vs BLS  O                    \n<ol><li>
-  vs BLE  T                    <p>\n ;vs BLE  Q                    \n<pre> ;vs BLE  U                    \n<ul><li> ;vs BLE  O                    \n<ol><li>
 
   vs T    I                  </p><dl><dt> ;vs T    D                  </p><dl><dd> ;vs T    H                  "</p><hr>" ;vs T    _                  </p>
   vs Q    I                </pre><dl><dt> ;vs Q    D                </pre><dl><dd> ;vs Q    H                "</pre><hr>" ;vs Q    _                </pre>
@@ -1742,8 +1554,6 @@
   vs HD2  I                 </h2><dl><dt> ;vs HD2  D                 </h2><dl><dd> ;vs HD2  H                 "</h2><hr>" ;vs HD2  _                 </h2>
   vs HD3  I                 </h3><dl><dt> ;vs HD3  D                 </h3><dl><dd> ;vs HD3  H                 "</h3><hr>" ;vs HD3  _                 </h3>
   vs HD4  I                 </h4><dl><dt> ;vs HD4  D                 </h4><dl><dd> ;vs HD4  H                 "</h4><hr>" ;vs HD4  _                 </h4>
-  vs BLS  I                    \n<dl><dt> ;vs BLS  D                    \n<dl><dd> ;vs BLS  H                      \n<hr> ;vs BLS  _                    \n
-  vs BLE  I                    \n<dl><dt> ;vs BLE  D                    \n<dl><dd> ;vs BLE  H                      \n<hr> ;vs BLE  _                    \n
 
   vs T    HD2                  </p><h2 ;vs T    HD3                  </p><h3 ;vs T    HD4                  </p><h4
   vs Q    HD2                </pre><h2 ;vs Q    HD3                </pre><h3 ;vs Q    HD4                </pre><h4
@@ -1760,80 +1570,54 @@
   vs HD2  HD2                 </h2><h2 ;vs HD2  HD3                 </h2><h3 ;vs HD2  HD4                 </h2><h4
   vs HD3  HD2                 </h3><h2 ;vs HD3  HD3                 </h3><h3 ;vs HD3  HD4                 </h3><h4
   vs HD4  HD2                 </h4><h2 ;vs HD4  HD3                 </h4><h3 ;vs HD4  HD4                 </h4><h4
-  vs BLS  HD2                    \n<h2 ;vs BLS  HD3                    \n<h3 ;vs BLS  HD4                    \n<h4
-  vs BLE  HD2                    \n<h2 ;vs BLE  HD3                    \n<h3 ;vs BLE  HD4                    \n<h4
 
-  vs T    BLS                  </p>\n ;vs T    BLE                  </p>\n
-  vs Q    BLS                </pre>\n ;vs Q    BLE                </pre>\n
-  vs U    BLS                 </ul>\n ;vs U    BLE                 </ul>\n
-  vs O    BLS                 </ol>\n ;vs O    BLE                 </ol>\n
-  vs I    BLS                 </dl>\n ;vs I    BLE                 </dl>\n
-  vs D    BLS                 </dl>\n ;vs D    BLE                 </dl>\n
-  vs H    BLS                      \n ;vs H    BLE                      \n
-  vs TDE  BLS </tr></tbody></table>\n ;vs TDE  BLE </tr></tbody></table>\n
-  vs TDEH BLS </tr></thead></table>\n ;vs TDEH BLE </tr></thead></table>\n
-  vs FE   BLS                </pre>\n ;vs FE   BLE                </pre>\n
-  vs FI   BLS                </pre>\n ;vs FI   BLE                </pre>\n
-  vs L    BLS         </tr></table>\n ;vs L    BLE              </table>\n
-  vs HD2  BLS                 </h2>\n ;vs HD2  BLE                 </h2>\n
-  vs HD3  BLS                 </h3>\n ;vs HD3  BLE                 </h3>\n
-  vs HD4  BLS                 </h4>\n ;vs HD4  BLE                 </h4>\n
-  vs BLS  BLS                      \n ;vs BLS  BLE                      \n
-  vs BLE  BLS                      \n ;vs BLE  BLE                      \n
-
-  vs T    L   "</p><table summary='' class=wikit_options><tr>"
-  vs Q    L "</pre><table summary='' class=wikit_options><tr>"
-  vs U    L  "</ul><table summary='' class=wikit_options><tr>"
-  vs O    L  "</ol><table summary='' class=wikit_options><tr>"
-  vs I    L  "</dl><table summary='' class=wikit_options><tr>"
-  vs D    L  "</dl><table summary='' class=wikit_options><tr>"
-  vs H    L       "<table summary='' class=wikit_options><tr>"
+  vs T    L   "</p><table cellspacing=0 cellpadding=0 summary='' class=wikit_options><tr>"
+  vs Q    L "</pre><table cellspacing=0 cellpadding=0 summary='' class=wikit_options><tr>"
+  vs U    L  "</ul><table cellspacing=0 cellpadding=0 summary='' class=wikit_options><tr>"
+  vs O    L  "</ol><table cellspacing=0 cellpadding=0 summary='' class=wikit_options><tr>"
+  vs I    L  "</dl><table cellspacing=0 cellpadding=0 summary='' class=wikit_options><tr>"
+  vs D    L  "</dl><table cellspacing=0 cellpadding=0 summary='' class=wikit_options><tr>"
+  vs H    L       "<table cellspacing=0 cellpadding=0 summary='' class=wikit_options><tr>"
   vs TDE  L                                        "</tr><tr>"
   vs TDEH L                                        "</tr><tr>"
-  vs FE   L "</pre><table summary='' class=wikit_options><tr>"
-  vs FI   L       "<table summary='' class=wikit_options><tr>"
+  vs FE   L "</pre><table cellspacing=0 cellpadding=0 summary='' class=wikit_options><tr>"
+  vs FI   L       "<table cellspacing=0 cellpadding=0 summary='' class=wikit_options><tr>"
   vs L    L                                             "<tr>"
-  vs HD2  L  "</h2><table summary='' class=wikit_options><tr>"
-  vs HD3  L  "</h3><table summary='' class=wikit_options><tr>"
-  vs HD4  L  "</h4><table summary='' class=wikit_options><tr>"
-  vs BLS  L     "\n<table summary='' class=wikit_options><tr>"
-  vs BLE  L     "\n<table summary='' class=wikit_options><tr>"
-
-  vs T    TR   "</p><table summary='' class=wikit_table><tbody><tr class='\$oddoreven'>"
-  vs Q    TR "</pre><table summary='' class=wikit_table><tbody><tr class='\$oddoreven'>"
-  vs U    TR  "</ul><table summary='' class=wikit_table><tbody><tr class='\$oddoreven'>"
-  vs O    TR  "</ol><table summary='' class=wikit_table><tbody><tr class='\$oddoreven'>"
-  vs I    TR  "</dl><table summary='' class=wikit_table><tbody><tr class='\$oddoreven'>"
-  vs D    TR  "</dl><table summary='' class=wikit_table><tbody><tr class='\$oddoreven'>"
-  vs H    TR       "<table summary='' class=wikit_table><tbody><tr class='\$oddoreven'>"
+  vs HD2  L  "</h2><table cellspacing=0 cellpadding=0 summary='' class=wikit_options><tr>"
+  vs HD3  L  "</h3><table cellspacing=0 cellpadding=0 summary='' class=wikit_options><tr>"
+  vs HD4  L  "</h4><table cellspacing=0 cellpadding=0 summary='' class=wikit_options><tr>"
+
+  vs T    TR   "</p><table cellspacing=0 cellpadding=0 summary='' class=wikit_table><tbody><tr class='\$oddoreven'>"
+  vs Q    TR "</pre><table cellspacing=0 cellpadding=0 summary='' class=wikit_table><tbody><tr class='\$oddoreven'>"
+  vs U    TR  "</ul><table cellspacing=0 cellpadding=0 summary='' class=wikit_table><tbody><tr class='\$oddoreven'>"
+  vs O    TR  "</ol><table cellspacing=0 cellpadding=0 summary='' class=wikit_table><tbody><tr class='\$oddoreven'>"
+  vs I    TR  "</dl><table cellspacing=0 cellpadding=0 summary='' class=wikit_table><tbody><tr class='\$oddoreven'>"
+  vs D    TR  "</dl><table cellspacing=0 cellpadding=0 summary='' class=wikit_table><tbody><tr class='\$oddoreven'>"
+  vs H    TR       "<table cellspacing=0 cellpadding=0 summary='' class=wikit_table><tbody><tr class='\$oddoreven'>"
   vs TDE  TR                                             "</tr><tr class='\$oddoreven'>"
   vs TDEH TR                              "</tr></thead><tbody><tr class='\$oddoreven'>"
-  vs FE   TR "</pre><table summary='' class=wikit_table><tbody><tr class='\$oddoreven'>"
-  vs FI   TR       "<table summary='' class=wikit_table><tbody><tr class='\$oddoreven'>"
+  vs FE   TR "</pre><table cellspacing=0 cellpadding=0 summary='' class=wikit_table><tbody><tr class='\$oddoreven'>"
+  vs FI   TR       "<table cellspacing=0 cellpadding=0 summary='' class=wikit_table><tbody><tr class='\$oddoreven'>"
   vs L    TR                                           "<tbody><tr class='\$oddoreven'>"
-  vs HD2  TR  "</h2><table summary='' class=wikit_table><tbody><tr class='\$oddoreven'>"
-  vs HD3  TR  "</h3><table summary='' class=wikit_table><tbody><tr class='\$oddoreven'>"
-  vs HD4  TR  "</h4><table summary='' class=wikit_table><tbody><tr class='\$oddoreven'>"
-  vs BLS  TR     "\n<table summary='' class=wikit_table><tbody><tr class='\$oddoreven'>"
-  vs BLE  TR     "\n<table summary='' class=wikit_table><tbody><tr class='\$oddoreven'>"
+  vs HD2  TR  "</h2><table cellspacing=0 cellpadding=0 summary='' class=wikit_table><tbody><tr class='\$oddoreven'>"
+  vs HD3  TR  "</h3><table cellspacing=0 cellpadding=0 summary='' class=wikit_table><tbody><tr class='\$oddoreven'>"
+  vs HD4  TR  "</h4><table cellspacing=0 cellpadding=0 summary='' class=wikit_table><tbody><tr class='\$oddoreven'>"
   
-  vs T    TRH   "</p><table summary='' class=wikit_table><thead><tr>"
-  vs Q    TRH "</pre><table summary='' class=wikit_table><thead><tr>"
-  vs U    TRH  "</ul><table summary='' class=wikit_table><thead><tr>"
-  vs O    TRH  "</ol><table summary='' class=wikit_table><thead><tr>"
-  vs I    TRH  "</dl><table summary='' class=wikit_table><thead><tr>"
-  vs D    TRH  "</dl><table summary='' class=wikit_table><thead><tr>"
-  vs H    TRH       "<table summary='' class=wikit_table><thead><tr>"
-  vs TDE  TRH                              "</tr></tbody><thead><tr>"
-  vs TDEH TRH                              "</tr></tbody><thead><tr>"
-  vs FE   TRH "</pre><table summary='' class=wikit_table><thead><tr>"
-  vs FI   TRH       "<table summary='' class=wikit_table><thead><tr>"
-  vs L    TRH                                           "<thead><tr>"
-  vs HD2  TRH  "</h2><table summary='' class=wikit_table><thead><tr>"
-  vs HD3  TRH  "</h3><table summary='' class=wikit_table><thead><tr>"
-  vs HD4  TRH  "</h4><table summary='' class=wikit_table><thead><tr>"
-  vs BLS  TRH     "\n<table summary='' class=wikit_table><thead><tr>"
-  vs BLE  TRH     "\n<table summary='' class=wikit_table><thead><tr>"
+  vs T    TRH   "</p><table cellspacing=0 cellpadding=0 summary='' class=wikit_table><thead><tr class='wikit_table_header'>"
+  vs Q    TRH "</pre><table cellspacing=0 cellpadding=0 summary='' class=wikit_table><thead><tr class='wikit_table_header'>"
+  vs U    TRH  "</ul><table cellspacing=0 cellpadding=0 summary='' class=wikit_table><thead><tr class='wikit_table_header'>"
+  vs O    TRH  "</ol><table cellspacing=0 cellpadding=0 summary='' class=wikit_table><thead><tr class='wikit_table_header'>"
+  vs I    TRH  "</dl><table cellspacing=0 cellpadding=0 summary='' class=wikit_table><thead><tr class='wikit_table_header'>"
+  vs D    TRH  "</dl><table cellspacing=0 cellpadding=0 summary='' class=wikit_table><thead><tr class='wikit_table_header'>"
+  vs H    TRH       "<table cellspacing=0 cellpadding=0 summary='' class=wikit_table><thead><tr class='wikit_table_header'>"
+  vs TDE  TRH                              "</tr></tbody><thead><tr class='wikit_table_header'>"
+  vs TDEH TRH                              "</tr></tbody><thead><tr class='wikit_table_header'>"
+  vs FE   TRH "</pre><table cellspacing=0 cellpadding=0 summary='' class=wikit_table><thead><tr class='wikit_table_header'>"
+  vs FI   TRH       "<table cellspacing=0 cellpadding=0 summary='' class=wikit_table><thead><tr class='wikit_table_header'>"
+  vs L    TRH                                           "<thead><tr class='wikit_table_header'>"
+  vs HD2  TRH  "</h2><table cellspacing=0 cellpadding=0 summary='' class=wikit_table><thead><tr class='wikit_table_header'>"
+  vs HD3  TRH  "</h3><table cellspacing=0 cellpadding=0 summary='' class=wikit_table><thead><tr class='wikit_table_header'>"
+  vs HD4  TRH  "</h4><table cellspacing=0 cellpadding=0 summary='' class=wikit_table><thead><tr class='wikit_table_header'>"
 
   vs T    FI                  </p><pre> ;vs T   FE                  </p> ;
   vs Q    FI                </pre><pre> ;vs Q   FE                </pre> ;
@@ -1850,17 +1634,15 @@
   vs HD2  FI                 </h2><pre> ;vs HD2 FE                 </h2> ;
   vs HD3  FI                 </h3><pre> ;vs HD3 FE                 </h3> ;
   vs HD4  FI                 </h4><pre> ;vs HD4 FE                 </h4> ;
-  vs BLS  FI                    \n<pre> ;vs BLS FE                    \n ;
-  vs BLE  FI                    \n<pre> ;vs BLE FE                    \n ;
 
   # Only TR and TDE can go to TD
   # TDE -> TDE is never required.
-  vs TR  TD  <td>
-  vs TDE TD  <td>
+  vs TR  TD  {<td class="${oddoreven}_cell">}
+  vs TDE TD  {<td class="${oddoreven}_cell">}
   vs TD  TDE </td>
 
-  vs TRH  TDH  <th>
-  vs TDEH TDH  <th>
+  vs TRH  TDH  {<th class="wikit_table_header_cell">}
+  vs TDEH TDH  {<th class="wikit_table_header_cell">}
   vs TDH  TDEH </th>
 
   vs L F "<td class=wikit_options><pre class=wikit_options>"
@@ -1871,16 +1653,23 @@
   vs V L </td></tr>
 
 proc l { pl t s e } { 
+  set t_lc [string tolower $t]
+  set ol_types [list 1 a i A I]
   variable html_frag
   set T T
   for { set l $s } { $l <= $e } { incr l } { 
 
     # From other type to U/O and back
     set sh ""
-    set eh "</li>"
+    set eh "\n</li>"
     for { set i 1} { $i <= $l } { incr i }  {
-      append sh <[string tolower $t]l>
-      append eh </[string tolower $t]l>
+      if {$t_lc eq "o"} {
+        set typeval [lindex $ol_types 0]
+        append sh "<${t_lc}l type=\"$typeval\" class=\"wikit_ol_depth_0\">"
+      } else {
+        append sh <${t_lc}l>
+      }
+      append eh </${t_lc}l>
     }
     append sh <li>
     foreach p $pl {
@@ -1893,24 +1682,29 @@
     }
 
     # Within same level U/O
-    vs $l$t $l$t </li><li>
+    vs $l$t $l$t "</li>\n<li>"
 
     # To other level U/O
     for { set i $s } { $i < $l } { incr i } { 
       set sh ""
       for { set j $i } { $j < $l } { incr j }  {
-        append sh "<[string tolower $t]l>"
+        if {$t_lc eq "o"} {
+          set typeval [lindex $ol_types [expr $i % [llength $ol_types]]]
+          append sh "<${t_lc}l type=\"$typeval\" class=\"wikit_ol_depth_$i\">"
+        } else {
+          append sh "<${t_lc}l>"
+        }
       }
       append sh "<li>"
       vs $i$t $l$t $sh
     }
 
     for { set i [expr {$l+1}] } { $i <= $e } { incr i } { 
-      set sh "</li>"
+      set sh "</li>\n"
       for { set j $i } { $j > $l } { incr j -1 }  {
-        append sh "</[string tolower $t]l>"
+        append sh "</${t_lc}l>"
       }
-      append sh "</li><li>"
+      append sh "</li>\n<li>"
       vs $i$t $l$t $sh
     }
   }
@@ -1919,17 +1713,19 @@
 proc il { s e } {
   set U U
   set O O
+  set ol_types [list 1 a i A I]
   for { set l $s } { $l <= $e } { incr l } { 
 
-    vs $l$U $l$O </li></ul><ol><li>
-    vs $l$O $l$U </li></ol><ul><li>
+    vs $l$U $l$O "</li></ul>\n<ol><li>"
+    vs $l$O $l$U "</li></ol>\n<ul><li>"
 
     for { set i $s } { $i < $l } { incr i } { 
       set ush ""
       set osh ""
       for { set j $i } { $j < $l } { incr j }  {
+        set typeval [lindex $ol_types [expr $j % [llength $ol_types]]]
+        append osh "<ol type=\"$typeval\" class=\"wikit_ol_depth_$j\">"
         append ush "<ul>"
-        append osh "<ol>"
       }
       append ush "<li>"
       append osh "<li>"
@@ -1938,14 +1734,14 @@
     }
 
     for { set i [expr {$l+1}] } { $i <= $e } { incr i } { 
-      set ush "</li></ul>"
-      set osh "</li></ol>"
+      set ush "</li>\n</ul>"
+      set osh "</li>\n</ol>"
       for { set j [expr {$i-1}] } { $j > $l } { incr j -1 }  {
         append ush "</ol>"
         append osh "</ul>"
       }
-      append ush "</li><li>"
-      append osh "</li><li>"
+      append ush "</li>\n<li>"
+      append osh "</li>\n<li>"
       vs $i$O $l$U $osh
       vs $i$U $l$O $ush
     }
@@ -1953,7 +1749,7 @@
   }
 }
 
-set pl {T Q I D H TDE TDEH FE FI L HD2 HD3 HD4 BLS BLE}
+set pl {T Q I D H TDE TDEH FE FI L HD2 HD3 HD4 TRH _}
 
 l $pl O 1 5
 l $pl U 1 5
@@ -2008,110 +1804,33 @@
     array get urls
   }
 
-  proc FormatWikiToc { C } {
-    variable protected
-    if { [string length $C] == 0 } {
-      return ""
-    }
-    set result ""
-    set toce ""
-    set imtoc {}
-    foreach line [split $C \n] {
-      if {[string length [string trim $line]]==0} continue
-      if {[string index $line 0] eq "+"} continue
-      if {[string is alnum [string index $line 0]]} {
-        if {[string length $result]} {
-          if {[string length $toce]} {
-            append result "<div class='toc3'>$toce</div>\n"
-            set toce ""
-          }
-          append result "</div>\n"
-        }
-        append result "<div class='toc1'>$line\n"
-      } elseif {[regexp {^\s*(.+?)\s+(\[.*\])\s*(.*)} $line - opt link imurl]} {
-        if {[string length $toce]} {
-          append result "<div class='toc2'>$toce</div>\n"
-        }
-        set link [string trim $link {[]}]
-        if { [string length $opt] } {
-          set p [::Wikit::LookupPage $link wdb]
-          set toce "<a class='toc' href='/$p'>[armour_quote $opt]</a>"
-          lappend imtoc [string trim $imurl] $p
-        } else {
-          set toce ""
-        }
-      }
-    }
-    if {[string length $toce]} {
-      append result "<div class='toc3'>$toce</div>\n"
-    }
-    if {[string length $result]} {
-      append result "</div>\n"
-    }
-    return [list $result $imtoc]
-  }
-
-  proc armour_quote { t } {
-    return [string map {\" &quot; ' &#39\;} $t]
-  }
-    
-  proc markInsDel { l insdelcntnm } {
-    upvar $insdelcntnm insdelcnt
-    set result ""
-    while {
-           [regsub -all {~~~~([^`]+?)~~~~} $l "\0\1o+\0\\1\0\1o-\0" l] ||
-           [regsub -all {\^\^\^\^([^`]+?)\^\^\^\^} $l "\0\1n+\0\\1\0\1n-\0" l]
-         } {}
-    
-    set len 0
-    foreach item [split $l \0] {
-      
-      set cmd [string trimleft $item \1]
-      
-      switch -exact -- $cmd {
-        n+      {append result "<ins id='diff$insdelcnt'>" ; incr insdelcnt}
-        n-      {append result </ins>}
-        o+      {append result "<del id='diff$insdelcnt'>" ; incr insdelcnt}
-        o-      {append result </del>}
-
-        default {
-          if {$cmd != ""} {
-            append result [quote $cmd]
-          }
-        }
-      }
-    }
-    return $result
-  }
-
-  proc ShowDiffs { t } {
-    set insdelcnt 0
-    set ctxt ""
-    set result "<pre class='prediff'>"
-    foreach l [split $t "\n"] {
-      if { [string match ">>>>>>*" $l] } { 
-        append result [markInsDel $ctxt insdelcnt]
-        set ctxt ""
-        foreach {bltype page version who when} [split [string range $l 6 end] ";"] break
-        if { $bltype eq "n" } {
-          append result "<div class='newwikiline' id='diff$insdelcnt'>"
-        } else {
-          append result "<div class='oldwikiline' id='diff$insdelcnt'>"
-        }
-        incr insdelcnt
-      } elseif { $l eq "<<<<<<" } {
-        append result [markInsDel $ctxt insdelcnt]
-        set ctxt ""
-        append result "</div>"
-      } else {
-        append ctxt $l\n
-      }
-    }
-    append result [markInsDel $ctxt insdelcnt]
-    append result </pre>
-    return $result
-  }
-
+	# sriv Return expanded stream for included page
+	proc IncludeStream {arg} {
+		set arg [string trim $arg]
+		# Avoid infinite recursion
+		if {[info level] > 100} {
+			puts stderr "IncludeStream: infinite recursion on $arg"
+			return {}
+		}
+		if {![regexp {^[0-9]+$} $arg]} {
+		# Search page by name
+			set pages [mk::select wdb.pages name $arg]
+			if {[set num [llength $pages]] != 1} {
+				puts stderr "IncludeStream: $num pages for $arg"
+				return {}
+			}
+			set arg [lindex $pages 0]
+		}
+		if {$arg < 10} {
+			# Don't include reserved pages
+			puts stderr "IncludeStream: invalid include $arg"
+			return {}
+		}
+		set page [Wikit::GetPage $arg]
+		set stream [TextToStream $page]
+		return $stream
+	}    
+	#sriv  
 } ;# end of namespace
 
 ### Local Variables: ***
