Skip to content

Commit 8c02202

Browse files
authored
Merge pull request #932 from nobu/markup-in-cells
Allow markup in cells
2 parents c8308eb + b16d3f1 commit 8c02202

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

lib/rdoc/markup/to_html.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -324,15 +324,15 @@ def accept_table header, body, aligns
324324
header.zip(aligns) do |text, align|
325325
@res << '<th'
326326
@res << ' align="' << align << '"' if align
327-
@res << '>' << CGI.escapeHTML(text) << "</th>\n"
327+
@res << '>' << to_html(text) << "</th>\n"
328328
end
329329
@res << "</tr>\n</thead>\n<tbody>\n"
330330
body.each do |row|
331331
@res << "<tr>\n"
332332
row.zip(aligns) do |text, align|
333333
@res << '<td'
334334
@res << ' align="' << align << '"' if align
335-
@res << '>' << CGI.escapeHTML(text) << "</td>\n"
335+
@res << '>' << to_html(text) << "</td>\n"
336336
end
337337
@res << "</tr>\n"
338338
end

test/rdoc/test_rdoc_markup_to_html.rb

+27
Original file line numberDiff line numberDiff line change
@@ -876,5 +876,32 @@ def util_format text
876876
@to.end_accepting
877877
end
878878

879+
def test_accept_table
880+
header = %w[Col1 Col2 Col3]
881+
body = [
882+
%w[cell1_1 cell1_2 cell1_3],
883+
%w[cell2_1 cell2_2 cell2_3],
884+
['<script>alert("foo");</script>',],
885+
%w[+code+ _em_ **strong**],
886+
]
887+
aligns = [:left, :right, nil]
888+
@to.start_accepting
889+
@to.accept_table(header, body, aligns)
890+
res = @to.end_accepting
891+
assert_include(res[%r<<th[^<>]*>Col1</th>>], 'align="left"')
892+
assert_include(res[%r<<th[^<>]*>Col2</th>>], 'align="right"')
893+
assert_not_include(res[%r<<th[^<>]*>Col3</th>>], 'align=')
894+
assert_include(res[%r<<td[^<>]*>cell1_1</td>>], 'align="left"')
895+
assert_include(res[%r<<td[^<>]*>cell1_2</td>>], 'align="right"')
896+
assert_not_include(res[%r<<td[^<>]*>cell1_3</td>>], 'align=')
897+
assert_include(res[%r<<td[^<>]*>cell2_1</td>>], 'align="left"')
898+
assert_include(res[%r<<td[^<>]*>cell2_2</td>>], 'align="right"')
899+
assert_not_include(res[%r<<td[^<>]*>cell2_3</td>>], 'align=')
900+
assert_not_include(res, '<script>')
901+
assert_include(res[%r<<td[^<>]*>.*script.*</td>>], '&lt;script&gt;')
902+
assert_include(res[%r<<td[^<>]*>.*code.*</td>>], '<code>code</code>')
903+
assert_include(res[%r<<td[^<>]*>.*em.*</td>>], '<em>em</em>')
904+
assert_include(res[%r<<td[^<>]*>.*strong.*</td>>], '<strong>strong</strong>')
905+
end
879906
end
880907

0 commit comments

Comments
 (0)