CSV to HTML translation: Difference between revisions

Content added Content deleted
Line 1,623: Line 1,623:


=={{header|Factor}}==
=={{header|Factor}}==
<lang factor>USING: combinators csv io kernel sequences strings ;
<lang factor>USING: csv html.streams prettyprint xml.writer ;
IN: rosetta-code.csv-to-html

CONSTANT: input


"Character,Speech
"Character,Speech
Line 1,635: Line 1,632:
The multitude,Behold his mother! Behold his mother!"
The multitude,Behold his mother! Behold his mother!"


string>csv [ simple-table. ] with-html-writer pprint-xml</lang>
: escape-chars ( seq -- seq' )
[
{
{ CHAR: & [ "&amp;" ] }
{ CHAR: ' [ "&apos;" ] }
{ CHAR: < [ "&lt;" ] }
{ CHAR: > [ "&gt;" ] }
[ 1string ]
} case
] { } map-as concat ;
: tag ( str tag -- <tag>str</tag> )
[ "<" ">" surround ] [ "</" ">" surround ] bi surround ;
: csv>table ( seq -- str )
[ [ "td" tag ] map concat "tr" tag " " prepend ] map
{ "<table>" } prepend { "</table>" } append "\n" join ;
input escape-chars string>csv csv>table print</lang>
{{out}}
{{out}}
<lang html5><table>
<lang html5><table style="display: inline-table; border-collapse: collapse;">
<tr>
<tr><td>Character</td><td>Speech</td></tr>
<td valign="top" style="border: 1px solid #cccccc; padding: 2px; ">
<tr><td>The multitude</td><td>The messiah! Show us the messiah!</td></tr>
Character
<tr><td>Brians mother</td><td>&lt;angry&gt;Now you listen here! He&apos;s not the messiah; he&apos;s a very naughty boy! Now go away!&lt;/angry&gt;</td></tr>
</td>
<tr><td>The multitude</td><td>Who are you?</td></tr>
<td valign="top" style="border: 1px solid #cccccc; padding: 2px; ">
<tr><td>Brians mother</td><td>I&apos;m his mother; that&apos;s who!</td></tr>
Speech
<tr><td>The multitude</td><td>Behold his mother! Behold his mother!</td></tr>
</td>
</table></lang>
</tr>
<tr>
<td valign="top" style="border: 1px solid #cccccc; padding: 2px; ">
The multitude
</td>
<td valign="top" style="border: 1px solid #cccccc; padding: 2px; ">
The messiah! Show us the messiah!
</td>
</tr>
<tr>
<td valign="top" style="border: 1px solid #cccccc; padding: 2px; ">
Brians mother
</td>
<td valign="top" style="border: 1px solid #cccccc; padding: 2px; ">
&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 valign="top" style="border: 1px solid #cccccc; padding: 2px; ">
The multitude
</td>
<td valign="top" style="border: 1px solid #cccccc; padding: 2px; ">
Who are you?
</td>
</tr>
<tr>
<td valign="top" style="border: 1px solid #cccccc; padding: 2px; ">
Brians mother
</td>
<td valign="top" style="border: 1px solid #cccccc; padding: 2px; ">
I'm his mother; that's who!
</td>
</tr>
<tr>
<td valign="top" style="border: 1px solid #cccccc; padding: 2px; ">
The multitude
</td>
<td valign="top" style="border: 1px solid #cccccc; padding: 2px; ">
Behold his mother! Behold his mother!
</td>
</tr>
</table>
<br/></lang>


=={{header|Forth}}==
=={{header|Forth}}==