RosettaCodeData/Task/CSV-to-HTML-translation/Jq/csv-to-html-translation-2.jq
2017-09-25 22:28:19 +02:00

22 lines
391 B
Text

def headerrow2html:
[" <thead> <tr>"]
+ (split(",") | map(" <th>\(@html)</th>"))
+ [ " </tr> </thead>" ]
;
def row2html:
[" <tr>"]
+ (split(",") | map(" <td>\(@html)</td>"))
+ [ " </tr>" ]
;
def csv2html:
def rows: reduce .[] as $row
([]; . + ($row | row2html));
["<table>"]
+ (.[0] | headerrow2html)
+ (.[1:] | rows)
+ [ "</table>"]
;
csv2html | .[]