Red []
csv: {Character,Speech
The multitude,The messiah! Show us the messiah!
Brians mother,Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!
The multitude,Who are you?
Brians mother,I'm his mother; that's who!
The multitude,Behold his mother! Behold his mother!}
add2html: func [ bl ] [append html rejoin bl ] ;; helper function to add block data to html string
;;----------------------------------------------------------------------
csv2html: func ["function to generate string with html table from csv data file"
;;----------------------------------------------------------------------
s [string!] "input .csv data"
][
arr: split s newline ;; generate array (series) from string
html: copy "
^/" ;; init html string
forall arr [ ;; i use forall here so that i can test for head? of series ...
either head? arr [ append html ""]
[ append html "
"]
replace/all first arr "<" "<" ;; escape "<" and ">" characters
replace/all first arr ">" ">"
foreach col split first arr "," [
either head? arr [
add2html ['| col ' | ]
][
add2html [' col ' | ]
]
]
add2html ['
newline]
]
return add2html ['
]
]
;;----------------------------------------------------------------------
print csv2html csv ;; call function
write %data.html csv2html csv ;; write to file