OpenWiki

Open Wiki/Extensions/Simpler Table Markup



Edit this page (last edited Januari 23, 2007)
Open Wiki | Sand Box | Create Page | User Preferences | Recent Changes | Title Index | Random Page | Find Page | Help
» Need for Student Apartments » jewelry » Baby Stuff For Free » Gainesville-bike-shop » Open Wiki/Extensions/Simpler Table Markup

Simpler Wiki Tables

Open Wiki tables are somewhat cumbersome to use, and can be difficult to read when editing. Here is an alternate markup for tables that is much easier to work with. If you have used bullet points on the wiki, then you can use this new table formatting.

New markup created by MikeyP - 01/09/07

  • Simpler Wiki Tables
  • Tables are Written Like Lists
  • Columns are Indented
  • Span Columns With Added Pipes
  • Table Headings are Noted with a Bang
  • Example
  • Adding Simple Tables to Your OpenWiki
  • Comments / Bugs
  • Note that the original Open Wiki table formatting still works (see Help On Tables).

    Also note that the below examples are mocked-up, as this installation of Open Wiki does not use this new markup.


    Tables are Written Like Lists

    Where bullet lists use the asterisk (*) character, tables use the "pipe" (|) character. As with lists, the pipe character must be prefixed with two spaces.

    Here is a list:
    
      * List Item One
      * List Item Two
      * List Item Three
    
    Here is a table:
    
      | Row One
      | Row Two
      | Row Three
    

    Here is a list:

    Here is a table:

    Row One
    Row Two
    Row Three

    Columns are Indented

    To add columns to rows, just indent two more spaces before the pipe character.

    Here is a table with some rows:
    
      | Row One, Column One
        | Row One, Column Two
        | Row One, Column Three
      | Row Two, Column One
        | Row Two, Column Two
        | Row Two, Column Three
    

    Row One, Column One Row One, Column Two Row One, Column Three
    Row Two, Column One Row Two, Column Two Row Two, Column Three

    Span Columns With Added Pipes

    Columns can be spanned by simply adding more pipe characters. For example, if you want to span two columns, use two pipe characters.

    Here is a table with rows that span multiple columns:
    
      ||| Row One, Spans Three Columns
      | Row Two, Column One
        || Row Two, Spans Two Columns
      | Row Three, Column One
        | Row Three, Column Two
        | Row Three, Column Three
    
    Here is a table with a row that span multiple columns:

    Row One, Spans Three Columns
    Row Two, Column One Row Two, Spans Two Columns
    Row Three, Column One Row Three, Column Two Row Three, Column Three

    Table Headings are Noted with a Bang

    The "bang" characater (!), aka exclaimation point, can be used to specify a row as a table header (which uses the HTML markup tag <TH> instead of <TD>). Just add the bang after the pipe character(s).

    Here is a table with a row marked as a table header:
    
      |! Row One, Column One
        | Row One, Column Two
        | Row One, Column Three
      | Row Two, Column One
        | Row Two, Column Two
        | Row Two, Column Three
    
    

    Row One, Column One Row One, Column Two Row One, Column Three
    Row Two, Column One Row Two, Column Two Row Two, Column Three

    Example

    Here is a pratical example of a table in use:

      ||||! Distribution
      |! Neighborhood
        | Unit Cost
        | Budget
        | Number of Sellers
      | Little Italy 
        | $1
        | $1000
        | 2
      | Brooklyn 
        | $2 
        | $2000 
        | 3
      | New Jersey 
        | $3 
        | $3000
        | 4
      | Hell's Kitchen 
        | $4 
        | $4000
        | 5
      | Midtown
        | $5 
        | $5000
        | 6
    

    Distribution
    Neighborhood Unit Cost Budget Number of Sellers
    Little Italy $1 $1000 1
    Brooklyn $2 $2000 2
    New Jersey $3 $3000 3
    Hell's Kitchen $4 $4000 4
    Midtown $5 $5000 5


    Adding Simple Tables to Your OpenWiki

    To use this simplified table markup on your Open Wiki installation, you need to modify the file ow\my\mywikify.asp. You can use the new table markup along with the original markup simultaneously.

    First, add the line pText = MySimpleTables(pText) to the MyMultiLineMarkupEnd function in mywikify.asp. The function should end up looking something like this:

    Function MyMultiLineMarkupEnd(pText)
       
        pText = MySimpleTables(pText)
           
        MyMultiLineMarkupEnd = pText
    
    End Function
    

    Then, simply add the following code to mywikify.asp. You can just paste it at the end of the file.

    Function MySimpleTables(pText)
    
            Dim vRegEx, vMatches, vMatch, vText, vLine
            Dim vInTable, vUseTH
            Dim vColSpan
                    
            vInTable = 0
    
            ' First, slurp the text into a regex vector that is parsed line by line
            Set vRegEx = New RegExp
            vRegEx.IgnoreCase = False
            vRegEx.Global = True
            vRegEx.Pattern = ".+"
            Set vMatches = vRegEx.Execute(pText)
            
            ' walk the lines
            For Each vMatch In vMatches
                    vLine = RTrim(Replace(vMatch.Value, vbCR, ""))
                    
                    ' if we find "        |" at the start of a line, that's a table
                    ' it will continue to be a table until we find a blank line
                    If Left(vLine, 3) = "  |" Then
                            ' count the number of pipes to set the table colspan
                            vColSpan = MyGetPipeCount(vLine,3)
                            ' check for a ! after the pipes to use TH instead of TD
                            vUseTH = m(vLine, "^  [|]+[!]", false, true)
                            ' replace the pipes with table HTML, using TH or TD where appropriate
                            If vUseTH Then
                                    vLine = s(vLine, "^  [|]+[!]", "<tr class=""wiki""><th class=""wiki"" colspan = """ & vColSpan & """>", False, True) & "</th>"
                            Else
                                    vLine = s(vLine, "^  [|]+", "<tr class=""wiki""><td class=""wiki"" colspan = """ & vColSpan & """>", False, True) & "</td>"
                            End If
                            ' if this is the beginning of a new table, prefix line with TABLE html, otherwise, assume the end of a row (TR)
                            If vInTable = 0 Then
                                    vLine = "<table class=""wiki"">" & vLine
                                    vInTable = 1
                            Else
                                    vLine = "</tr>" & vLine
                            End If
                    End If
    
                    'This code looks almost identical to the block above
                    ' if we find "          |", that's another column in a table
                    If Left(vLine, 5) = "         |" And vInTable = 1 Then
                            vColSpan = MyGetPipeCount(vLine,5)
                            ' assume entire row is marked as TH
                            If vUseTH Then
                                    vLine = s(vLine, "^    [|]+", "<th class=""wiki"" colspan = """ & vColSpan & """>", False, True) & "</th>"
                            Else
                                    vLine = s(vLine, "^    [|]+", "<td class=""wiki"" colspan = """ & vColSpan & """>", False, True) & "</td>"
                            End If
                    End If
                    
                    ' a blank line means that the table is done, so write the /TABLE HTML        
                    If vLine = "" And vInTable = 1 Then
                            vInTable = 0
                            vLine = vLine & "</tr></table>"
                    End If
                    
                    vText = vText & vLine & vbCRLF
            Next
    
            ' if we didnt catch a blank line before, we should force the end of a table now
            If vInTable = 1 Then
                    vInTable = 0
                    vText = vText & "</tr></table>" & vbCRLF
            End If
    
            
            MySimpleTables = vText
            
    End Function
    
    Function MyGetPipeCount(pPipeText, pStartPos)
            
            ' this would probably be faster if it was done in regex instead
            
            Dim vCharPos, vPipeCount, vPipe
    
            vCharPos = pStartPos
            vPipeCount = 0
            Do
                    vPipe = Mid(pPipeText,vCharPos,1)
                    If vPipe = "|" Then
                            vPipeCount = vPipeCount + 1
                    End If
                    vCharPos = vCharPos + 1
            Loop While vPipe = "|"
            
            MyGetPipeCount = vPipeCount
    End Function
    


    Comments / Bugs

    Should use THEAD markup in the table header rows.


    Open Wiki | Sand Box | Create Page | User Preferences | Recent Changes | Title Index | Random Page | Find Page | Help
    Edit this page | View other revisions
    Print this page | View XML
    Find page by browsing, searching or an index
    Edited Januari 23, 2007 (diff)




    Valid XHTML 1.0!Valid CSS!

    Powered by OpenWiki.com