CSV to HTML translation: Difference between revisions
Content added Content deleted
(→{{header|UNIX Shell}}: simpler version (doesn't work with ksh anymore, though)) |
|||
Line 5,530: | Line 5,530: | ||
=={{header|UNIX Shell}}== |
=={{header|UNIX Shell}}== |
||
{{works with|bash}} |
{{works with|bash}} |
||
{{works with|ksh}} |
|||
<lang bash>csv2html() { |
<lang bash>csv2html() { |
||
IFS=, |
IFS=, |
||
echo "<table>" |
echo "<table>" |
||
echo "<thead>" |
echo "<thead>" |
||
read - |
read -a fields |
||
htmlrow |
htmlrow th "${fields[@]}" |
||
echo "</thead>" |
echo "</thead>" |
||
echo "<tbody>" |
echo "<tbody>" |
||
while read - |
while read -a fields |
||
do htmlrow td "${fields[@]}" |
|||
done |
done |
||
echo "</tbody>" |
echo "</tbody>" |
||
echo "</table>" |
echo "</table>" |
||
} |
} |
||
htmlrow() { |
htmlrow() { |
||
cell=$1 |
|||
shift |
|||
printf "<tr><%s>%s</%s><%s>%s</%s></tr>\n" \ |
|||
echo "<tr>" |
|||
⚫ | |||
for field |
|||
"$cell" "$(escape_html "$2")" "$cell" |
|||
⚫ | |||
done |
|||
⚫ | |||
} |
} |
||
escape_html() { |
escape_html() { |
||
str=${1//\&/&} |
str=${1//\&/&} |
||
Line 5,562: | Line 5,564: | ||
} |
} |
||
⚫ | |||
html=$( |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
The multitude,Behold his mother! Behold his mother! |
|||
END</lang> |
|||
⚫ | |||
END |
|||
) |
|||
⚫ | |||
{{output}} |
{{output}} |
||
<lang html5><table> |
<lang html5><table> |
||
<thead> |
<thead> |
||
<tr> |
|||
<th>Character</th> |
|||
<th>Speech</th> |
|||
</tr> |
|||
</thead> |
</thead> |
||
<tbody> |
<tbody> |
||
<tr> |
|||
<tr><td>The multitude</td><td>The messiah! Show us the messiah!</td></tr> |
|||
<td>The multitude</td> |
|||
⚫ | |||
<td>The messiah! Show us the messiah!</td> |
|||
</tr> |
|||
⚫ | |||
<tr> |
|||
<tr><td>The multitude</td><td>Behold his mother! Behold his mother!</td></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> |
</tbody> |
||
</table></lang> |
</table></lang> |