Stephen Bannasch
2007-Mar-24 16:30 UTC
Patch for superredcloth to enable textile table headers
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
Stephen Bannasch
2007-Mar-26 18:27 UTC
Patch for superredcloth to enable textile table headers
I updated my patch for table_headers here: http://code.whytheluckystiff.net/redcloth/ticket/9 I fixed a problem where it was breaking other functionality and and added more table tests. I copied some of the table tests in textism.yml to table.yml so I could test and work on just the table tests more easily. I didn''t changed textism.yml. There are now 8 tests in table.yml and only the last one still fails for just two reasons: 1. styles aren''t having a '';'' added if needed at the end of a style list 2. ''|.|'' aren''t being converted to <td> </td> Is #2 a feature of textile? I added a test for an empty table cell and it seems to work fine. This test passes: in: |- |a|b|c| | |2|3| out: |- <table> <tr> <td>a</td> <td>b</td> <td>c</td> </tr> <tr> <td> </td> <td>2</td> <td>3</td> </tr> </table> -- - Stephen Bannasch Concord Consortium, http://www.concord.org
why the lucky stiff
2007-Apr-20 02:28 UTC
Patch for superredcloth to enable textile table headers
On Mon, Mar 26, 2007 at 02:27:09PM -0400, Stephen Bannasch wrote:> I updated my patch for table_headers here: > > http://code.whytheluckystiff.net/redcloth/ticket/9 > > I fixed a problem where it was breaking other functionality and and > added more table tests.I finally got around to checking this in. I don''t know why it took me so long, cause this was a good patch, Stephen. _why
Stephen Bannasch
2007-Apr-20 07:14 UTC
Patch for superredcloth to enable textile table headers
>I finally got around to checking this in. I don''t know why it took >me so long, cause this was a good patch, Stephen.Great! -- I was just talking today with someone who needed the patched gem and was thinking it would be easier (especially if more people needed it) if I could point them to the real gem. I also get a kick out of having my patch in your code :-) It took a while to get into the ragel headspace -- it reminded me a bit of when I wrote my first assembly language programs. The resulting patch was simple but I didn''t take a direct path getting there. -- - Stephen Bannasch Concord Consortium, http://www.concord.org