CSV to HTML translation: Difference between revisions
Content added Content deleted
(→{{header|Haskell}}: compactify) |
(updating js example) |
||
Line 1,362:
=={{header|JavaScript}}==
<lang JavaScript>
var csv = "Character,Speech\n" +
Line 1,371 ⟶ 1,370:
"The multitude,Behold his mother! Behold his mother!";
csv = csv.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"');
var lines = csv.split(/[\n\r]+/g),
Line 1,380 ⟶ 1,379:
line,
rows = "",
thead = '<
'<th>'+header[0]+'</th>'+
'<th>'+header[1]+'</th>'+
'</
for (var i=0, len=lines.length; i<len; i++) {
Line 1,390 ⟶ 1,389:
'<td>'+line[0]+'</td>'+
'<td>'+line[1]+'</td>'+
'</tr>\n';
}
console.log('<table><thead>\n' + thead + '</thead><tbody>\n' + rows + '</tbody></table>' );
</lang>
<lang html>
<table><thead>
<tr><th>Character</th><th>Speech</th></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>
</lang>
|