Jump to content

CSV to HTML translation: Difference between revisions

Vedit macro language
(updating js example)
(Vedit macro language)
Line 2,455:
</lang>
=== Output (rendered) ===
[[file:tuscript_csv2html.png|500px|thumb|leftnone|rendered by browser ]]
 
 
=={{header|Vedit macro language}}==
 
This solution converts the table in-place in current edit buffer.
If a block is highlighted, only the block is converted. If no block highlighted, the entire file is converted.
 
<lang vedit>if (BB < 0) { // block not set
BB(0) // convert entire file
BE(File_Size)
}
 
// Convert special characters into entities
Replace_Block("&","&amp;", BB, BE, BEGIN+ALL+NOERR)
Replace_Block("<","&lt;", BB, BE, BEGIN+ALL+NOERR)
Replace_Block(">","&gt;", BB, BE, BEGIN+ALL+NOERR)
 
// Convert CSV into HTML table
Goto_Pos(BB)
IT('<table>') IN
#80 = Cur_Pos
Goto_Pos(BE)
IT("</table>")
#81 = Cur_Line
IN
Goto_Pos(#80)
while (Cur_Line < #81) {
IT(" ",COUNT,4)
IT("<tr><td>")
Replace_Block(",","</td><td>",Cur_Pos,EOL_Pos,ALL+NOERR)
EOL
IT("</td></tr>")
Line(1)
}
BB(Clear)</lang>
 
Output:
<lang html5><table>
<tr><td>Character</td><td>Speech </td></tr>
<tr><td>The multitude</td><td>The messiah! Show us the messiah! </td></tr>
<tr><td>Brians mother</td><td>&lt;angry&gt;Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!&lt;/angry&gt; </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>
</table></lang>
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.