Patch for superredcloth to enable textile table headers

Stephen Bannasch stephen at concord.org
Sat Mar 24 12:30:37 EDT 2007


SuperRedCloth v1.160 and svn rev 163 don't work the textile commands 
that specify table headers instead of table data.

Here's a simple test:

require 'superredcloth'
w = "|_. a|_. b|_. c|\n|1|2|3|"
h = SuperRedCloth.new(w).to_html
puts h

<table>
                 <tr>
                         <td>_. a</td>
                         <td>_. b</td>
                         <td>_. c</td>
                 </tr>
                 <tr>
                         <td>1</td>
                         <td>2</td>
                         <td>3</td>
                 </tr>
         </table>

I have a patch for svn rev 163 that fixes this and adds two tests 
(one for a very simple table, and a second with that same simple 
table with headers). The first test works now, the second works also 
with the patch.

It was fun learning a bit about ragel.

What's the best way to contribute it? I added it as a patch to my 
redcloth ticket about the problem:

   http://code.whytheluckystiff.net/redcloth/ticket/9

Here's what the patches look like as a svn diff:

$ svn diff
Index: test/table.yml
===================================================================
--- test/table.yml      (revision 163)
+++ test/table.yml      (working copy)
@@ -1,4 +1,39 @@
+---
  in: |
+  |a|b|c|
+  |1|2|3|
+out: |-
+  <table>
+               <tr>
+                       <td>a</td>
+                       <td>b</td>
+                       <td>c</td>
+               </tr>
+               <tr>
+                       <td>1</td>
+                       <td>2</td>
+                       <td>3</td>
+               </tr>
+       </table>
+---
+in: |
+  |_. a|_. b|_. c|
+  |1|2|3|
+out: |-
+  <table>
+               <tr>
+                       <th>a</th>
+                       <th>b</th>
+                       <th>c</th>
+               </tr>
+               <tr>
+                       <td>1</td>
+                       <td>2</td>
+                       <td>3</td>
+               </tr>
+       </table>
+---
+in: |
    {background:#ddd}. |S|Target|Complete|App|Milestone|
    |!/i/g.gif!|11/18/04|11/18/04|070|XML spec complete|
    |!/i/g.gif!|11/29/04|11/29/04|011|XML spec complete (KH is on schedule)|
Index: ext/superredcloth_scan/superredcloth_scan.rl
===================================================================
--- ext/superredcloth_scan/superredcloth_scan.rl        (revision 163)
+++ ext/superredcloth_scan/superredcloth_scan.rl        (working copy)
@@ -37,9 +37,9 @@
    # tables
    para = ( default+ ) -- CRLF ;
    btext = para ( CRLF{2} )? ;
-  tddef = ( S A C :> dotspace ) ;
+  tddef = ( S A C D :> dotspace ) ;
    td = ( tddef? btext >A %T :> "|" >{PASS(table, text, td);} ) >X ;
-  trdef = ( A C :> dotspace ) ;
+  trdef = ( A C D :> dotspace ) ;
    tr = ( trdef? "|" %{INLINE(table, tr_open);} td+ ) >X 
%{INLINE(table, tr_close);} ;
    trows = ( tr (CRLF >X tr)* ) ;
    tdef = ( "table" >X A C :> dotspace CRLF ) ;
Index: ext/superredcloth_scan/superredcloth_common.rl
===================================================================
--- ext/superredcloth_scan/superredcloth_common.rl      (revision 163)
+++ ext/superredcloth_scan/superredcloth_common.rl      (working copy)
@@ -29,10 +29,12 @@
    C_STYL = ( "{" [^}]+ >A %{ STORE(style) } "}" ) ;
    S_CSPN = ( "\\" [0-9]+ >A %{ STORE(colspan) } ) ;
    S_RSPN = ( "/" [0-9]+ >A %{ STORE(rowspan) } ) ;
+  D_HEADER = "_" %{ ASET(th, true) } ;
    A = ( ( A_HLGN | A_VLGN )* ) ;
    A2 = ( A_LIMIT? ) ;
    S = ( S_CSPN | S_RSPN )* ;
    C = ( C_CLAS | C_STYL | C_LNGE )* ;
+  D = ( D_HEADER ) ;
    N_CONT = "_" %{ ASET(start, continue) };
    N_NUM = digit+ >A %{ STORE(start) };
    N = ( N_CONT | N_NUM )? ;
Index: lib/superredcloth.rb
===================================================================
--- lib/superredcloth.rb        (revision 163)
+++ lib/superredcloth.rb        (working copy)
@@ -46,7 +46,8 @@
      "<p>" + txt + "</p>"
    end
    def td opts
-    "\t\t\t<td#{pba(opts)}>#{opts[:text]}</td>\n"
+    tdtype = opts[:th] ? 'th' : 'td'
+    "\t\t\t<#{tdtype}#{pba(opts)}>#{opts[:text]}</#{tdtype}>\n"
    end
    def tr_open opts
      "\t\t<tr#{pba(opts)}>\n"
[~/dev/rails/why/superredcloth]$ svn up
At revision 163.
[~/dev/rails/why/superredcloth]$ ruby test_table.rb
<table>
                 <tr>
                         <td>_. a</td>
                         <td>_. b</td>
                         <td>_. c</td>
                 </tr>
                 <tr>
                         <td>1</td>
                         <td>2</td>
                         <td>3</td>
                 </tr>
         </table>


-- 
- Stephen Bannasch
   Concord Consortium, http://www.concord.org


More information about the Redcloth-upwards mailing list