CSV to HTML translation: Difference between revisions

no edit summary
(category:)
No edit summary
Line 3,225:
<tr><td>The multitude</td><td>Behold his mother! Behold his mother!</td></tr>
</table></syntaxhighlight>
 
=={{header|M2000 Interpreter}}==
 
<syntaxhighlight lang="m2000 interpreter">
module csv2html {
nl$={
}
Repl$=lambda$ (a$) ->{
a$=replace$("&", "&amp;",a$)
a$=replace$(">", "&gt;",a$)
a$=replace$("""", "&quot;",a$)
// add any other replacement here
=replace$("<", "&lt;",a$)
}
Tag$=lambda$ nl$, repl$ (a$, b$, n=4)->{
if n>0 then
a$=rtrim$(replace$(nl$, nl$+string$(" ", n), nl$+a$))
if right$(a$,2)<>nl$ then a$+=nl$
else
if right$(a$, 2)=nl$ then if left$(a$,2)<>nl$ then a$=nl$+a$
end if
prop=(,) : Read ? prop // forth parameter optional (we have to initalize first with an empty array)
p=each(prop) : prop$="" // p is an iteration object.
while p
prop$+=" "+repl$(prop#val$(p^))+"="+quote$(repl$(prop#val$(p^+1)))
p=each(prop,p^+2) // start new from p^+2 (p^ is the internal counter)
end while
="<"+b$+prop$+">"+a$+"</"+b$+">"+nl$
}
// Prepare FILE csv
tofile$={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?
Brians mother,I'm his mother; that's who!
The multitude,Behold his mother! Behold his mother!
}
open "forHtml.csv" for wide output as #f
Print #f, tofile$;
close #f
// prepare the input style for Input from file statement
// "," - we use comma between fields
// "." - for numbers we use dot for decimal separator
// false - we didn't read json style strings to normal strings (so \n convert to code 13, \t to code 9)
// true - we read strings unquote
input with ",",".",false, true
// Read csv file
i=1
document export$=""
Open "forHtml.csv" for wide input as #f
while not eof(#f)
input #f, a$, b$
a$=repl$(a$)
b$=repl$(b$)
if i=1 then
export$+=tag$(tag$(a$, "th", 0)+tag$(b$,"th", 0), "tr", 4)
else
export$+=tag$(tag$(a$, "td", 0)+tag$(b$,"td", 0), "tr", 4)
end if
i++
end while
close #f
style$=tag$({TD {background-color:#ddddff; }
thead TD {background-color:#ddffdd; text-align:center; }
}," style",4,("type", "text/css"))
title$= tag$("CSV to HTML translation - Extra Credit","title",0)
Head$= tag$(title$+ style$,"head")
html$=tag$(head$+tag$(export$, "body"), "html")
clipboard html$
Report html$
}
csv2html
</syntaxhighlight>
{{out}}
<pre>
<html>
<head>
<title>CSV to HTML translation - Extra Credit</title>
< style type="text/css">
TD {background-color:#ddddff; }
thead TD {background-color:#ddffdd; text-align:center; }
</ style>
</head>
<body>
<tr>
<th>Character</th>
<th>Speech</th>
</tr>
<tr>
<td>The multitude</td>
<td>The messiah! Show us the messiah!</td>
</tr>
<tr>
<td>Brians mother</td>
<td>&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>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>
<td>Behold his mother! Behold his mother!</td>
</tr>
</body>
</html>
 
</pre>
 
=={{header|Maple}}==
404

edits