Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -5,26 +5,14 @@ var csv = "Character,Speech\n" +
|
|||
"Brians mother,I'm his mother; that's who!\n" +
|
||||
"The multitude,Behold his mother! Behold his mother!";
|
||||
|
||||
csv = csv.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"');
|
||||
var lines = csv.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.split(/[\n\r]/)
|
||||
.map(function(line) { return line.split(',')})
|
||||
.map(function(row) {return '\t\t<tr><td>' + row[0] + '</td><td>' + row[1] + '</td></tr>';});
|
||||
|
||||
var lines = csv.split(/[\n\r]+/g),
|
||||
header = lines.shift().split(","),
|
||||
line,
|
||||
rows = "",
|
||||
thead = '<tr>'+
|
||||
'<th>'+header[0]+'</th>'+
|
||||
'<th>'+header[1]+'</th>'+
|
||||
'</tr>\n';
|
||||
|
||||
for (var i=0, len=lines.length; i<len; i++) {
|
||||
line = lines[i].split(",");
|
||||
rows += '<tr>'+
|
||||
'<td>'+line[0]+'</td>'+
|
||||
'<td>'+line[1]+'</td>'+
|
||||
'</tr>\n';
|
||||
}
|
||||
|
||||
console.log('<table><thead>\n' + thead + '</thead><tbody>\n' + rows + '</tbody></table>' );
|
||||
console.log('<table>\n\t<thead>\n' + lines[0] +
|
||||
'\n\t</thead>\n\t<tbody>\n' + lines.slice(1).join('\n') +
|
||||
'\t</tbody>\n</table>');
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
<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>
|
||||
<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>
|
||||
|
|
|
|||
|
|
@ -1,20 +1,11 @@
|
|||
function csv_to_table(s) {
|
||||
function ce(t) { return document.createElement(t); }
|
||||
function ap(t) { document.body.appendChild(t); }
|
||||
var t = ce('table'), f = 0; //1;
|
||||
s.split('\n').map(function(l) {
|
||||
var r = ce(f ? 'tr': 'thead');
|
||||
l.split(',').map(function (w) {
|
||||
var c = ce(f ? 'td' : 'th');
|
||||
c.textContent = w;
|
||||
r.appendChild(c);
|
||||
});
|
||||
t.appendChild(r);
|
||||
f = 1; //0;
|
||||
});
|
||||
//return t.innerHTML;
|
||||
return t.outerHTML;
|
||||
}
|
||||
/*
|
||||
but also with this changes is very dependent by javascript engine and/or browser version (in: IE>=9, chrome )
|
||||
*/
|
||||
<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>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue