CSV to HTML translation: Difference between revisions
→{{header|UNIX Shell}}: simpler version (doesn't work with ksh anymore, though)
(→{{header|UNIX Shell}}: simpler version (doesn't work with ksh anymore, though)) |
|||
Line 5,530:
=={{header|UNIX Shell}}==
{{works with|bash}}
<lang bash>csv2html() {
IFS=,
echo "<table>"
echo "<thead>"
read -
htmlrow
echo "</thead>"
echo "<tbody>"
while read -
done
echo "</tbody>"
echo "</table>"
}
htmlrow() {
shift
echo "<tr>"
"$cell" "$(escape_html "$1")" "$cell" \▼
for field
done
}
escape_html() {
str=${1//\&/&}
Line 5,562 ⟶ 5,564:
}
▲ csv2html <<-END
▲ Character,Speech
▲ 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>
▲ The multitude,Who are you?
END</lang>
The multitude,Behold his mother! Behold his mother!▼
▲echo "$html"</lang>
{{output}}
<lang html5><table>
<thead>
<tr>
<th>Speech</th>
</tr>
</thead>
<tbody>
<tr>
<td>The multitude</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>
▲<tr><td>Brians mother</td><td>I'm his mother; that's who!</td></tr>
<tr>
<td>Brians mother</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>
</tr>
</tbody>
</table></lang>
|