CSV to HTML translation: Difference between revisions
Content added Content deleted
m (→{{header|J}}: display output using lang html) |
(→{{header|J}}: tidy up) |
||
Line 118: | Line 118: | ||
<lang j>require 'strings tables/csv' |
<lang j>require 'strings tables/csv' |
||
encodeHTML=: ('&';'&';'<';'<';'>';'>')&stringreplace |
encodeHTML=: ('&';'&';'<';'<';'>';'>')&stringreplace |
||
cell=: '<td>' , ,&'</td>' |
cell=: ('<td>' , ,&'</td>')&.> |
||
row=: <@('<tr>' , ,&('</tr>',LF))@;"1 |
row=: <@('<tr>' , ,&('</tr>',LF))@;"1 |
||
table=: ('<table>' , ,&'</table>')@;"1 |
table=: (('<table>',LF) , ,&('</table>'))@;"1 |
||
makeHTMLtablefromCSV= |
makeHTMLtablefromCSV=: table@:row@:cell@fixcsv@encodeHTML</lang> |
||
'''Example''' |
'''Example''' |
||
<lang j> csvstrng=: noun define |
<lang j> csvstrng=: noun define |
||
Character,Speech |
Character,Speech |
||
The multitude,The messiah! Show us the messiah! |
The multitude,The messiah! Show us the messiah! |
||
Brians mother,<angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry> |
Brians mother,<angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry> |
||
The multitude,Who are you? |
The multitude,Who are you? |
||
Brians mother,I'm his mother; that's who! |
Brians mother,I'm his mother; that's who! |
||
The multitude,Behold his mother! Behold his mother! |
The multitude,Behold his mother! Behold his mother! |
||
) |
|||
)</lang> |
|||
⚫ | |||
HTML output: |
|||
⚫ | |||
<lang html><table> |
|||
<table><tr><td>Character</td><td>Speech </td></tr> |
|||
<tr><td> |
<tr><td>Character</td><td>Speech</td></tr> |
||
<tr><td> |
<tr><td>The multitude</td><td>The messiah! Show us the messiah!</td></tr> |
||
<tr><td> |
<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> |
<tr><td>The multitude</td><td>Who are you?</td></tr> |
||
<tr><td> |
<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> |
</table></lang> |
||