36 lines
1.5 KiB
Text
36 lines
1.5 KiB
Text
/* CSV to HTML, in Jsish */
|
|
var csv = "Character,Speech\n" +
|
|
"The multitude,The messiah! Show us the messiah!\n" +
|
|
"Brians mother,<angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry>\n" +
|
|
"The multitude,Who are you?\n" +
|
|
"Brians mother,I'm his mother; that's who!\n" +
|
|
"The multitude,Behold his mother! Behold his mother!";
|
|
|
|
var lines = csv.replace(/&/g, '&')
|
|
.replace(/</g, '<')
|
|
.replace(/>/g, '>')
|
|
.replace(/"/g, '"')
|
|
.split('\n')
|
|
.map(function(line) { return line.split(','); })
|
|
.map(function(row) { return '\t\t<tr><td>' + row[0] + '</td><td>' + row[1] + '</td></tr>'; });
|
|
|
|
if (Interp.conf('unitTest')) {
|
|
puts('<table>\n\t<thead>\n' + lines[0] + '\n\t</thead>\n\t<tbody>\n'
|
|
+ lines.slice(1).join('\n') + '\t</tbody>\n</table>');
|
|
}
|
|
|
|
/*
|
|
=!EXPECTSTART!=
|
|
<table>
|
|
<thead>
|
|
<tr><td>Character</td><td>Speech</td></tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr><td>The multitude</td><td>The messiah! Show us the messiah!</td></tr>
|
|
<tr><td>Brians mother</td><td><angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry></td></tr>
|
|
<tr><td>The multitude</td><td>Who are you?</td></tr>
|
|
<tr><td>Brians mother</td><td>I'm his mother; that's who!</td></tr>
|
|
<tr><td>The multitude</td><td>Behold his mother! Behold his mother!</td></tr> </tbody>
|
|
</table>
|
|
=!EXPECTEND!=
|
|
*/
|