September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -0,0 +1,54 @@
|
|||
// version 1.1.3
|
||||
|
||||
val csv =
|
||||
"Character,Speech\n" +
|
||||
"The multitude,The messiah! Show us the messiah!\n" +
|
||||
"Brians mother,<angry>Now you listen here! He's not the messiah; " +
|
||||
"he's a very naughty boy! Now go away!</angry>\n" +
|
||||
"The multitude,Who are you?\n" +
|
||||
"Brians mother,I'm his mother; that's who!\n" +
|
||||
"The multitude,Behold his mother! Behold his mother!"
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val i = " " // indent
|
||||
val sb = StringBuilder("<table>\n$i<tr>\n$i$i<td>")
|
||||
for (c in csv) {
|
||||
sb.append( when (c) {
|
||||
'\n' -> "</td>\n$i</tr>\n$i<tr>\n$i$i<td>"
|
||||
',' -> "</td>\n$i$i<td>"
|
||||
'&' -> "&"
|
||||
'\'' -> "'"
|
||||
'<' -> "<"
|
||||
'>' -> ">"
|
||||
else -> c.toString()
|
||||
})
|
||||
}
|
||||
sb.append("</td>\n$i</tr>\n</table>")
|
||||
println(sb.toString())
|
||||
println()
|
||||
|
||||
// now using first row as a table header
|
||||
sb.setLength(0)
|
||||
sb.append("<table>\n$i<thead>\n$i$i<tr>\n$i$i$i<td>")
|
||||
val hLength = csv.indexOf('\n') + 1 // find length of first row including CR
|
||||
for (c in csv.take(hLength)) {
|
||||
sb.append( when (c) {
|
||||
'\n' -> "</td>\n$i$i</tr>\n$i</thead>\n$i<tbody>\n$i$i<tr>\n$i$i$i<td>"
|
||||
',' -> "</td>\n$i$i$i<td>"
|
||||
else -> c.toString()
|
||||
})
|
||||
}
|
||||
for (c in csv.drop(hLength)) {
|
||||
sb.append( when (c) {
|
||||
'\n' -> "</td>\n$i$i</tr>\n$i$i<tr>\n$i$i$i<td>"
|
||||
',' -> "</td>\n$i$i$i<td>"
|
||||
'&' -> "&"
|
||||
'\'' -> "'"
|
||||
'<' -> "<"
|
||||
'>' -> ">"
|
||||
else -> c.toString()
|
||||
})
|
||||
}
|
||||
sb.append("</td>\n$i$i</tr>\n$i</tbody>\n</table>")
|
||||
println(sb.toString())
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
<table>
|
||||
<tr>
|
||||
<td>Character</td>
|
||||
<td>Speech</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>The multitude</td>
|
||||
<td>The messiah! Show us the messiah!</td>
|
||||
</tr>
|
||||
<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>
|
||||
<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>
|
||||
</table>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>Character</td>
|
||||
<td>Speech</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>The multitude</td>
|
||||
<td>The messiah! Show us the messiah!</td>
|
||||
</tr>
|
||||
<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>
|
||||
<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>
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
/*REXX program to convert CSV ───> HTML table representing the CSV data.*/
|
||||
/*REXX program to convert CSV ───> HTML table representing the CSV data.*/
|
||||
|
||||
arg header_ . /*see if the user wants a header.*/
|
||||
wantsHdr= (header_=='HEADER') /*arg (low/upp/mix case)=HEADER ?*/
|
||||
|
||||
iFID='CSV_HTML.TXT' /*the input fileID. */
|
||||
if wantsHdr then oFID='OUTPUTH.HTML' /*output fileID with header, */
|
||||
else oFID='OUTPUT.HTML' /* " " without header. */
|
||||
|
||||
do rows=0 while lines(iFID)\==0 /*read the rows from a (txt) file*/
|
||||
row.rows=strip(linein(iFID))
|
||||
end /*rows*/
|
||||
|
||||
convFrom= '& < > "' /*special characters to convert. */
|
||||
convTo = '& < > "' /*what they are converted into. */
|
||||
|
||||
call write ,'<html>'
|
||||
call write ,'<table border=4 cellpadding=9 cellspacing=1>'
|
||||
|
||||
do j=0 for rows; call write 5,'<tr>'
|
||||
tx='td'
|
||||
if wantsHdr & j==0 then tx='th'
|
||||
|
||||
do while row.j\==''; parse var row.j yyy ',' row.j
|
||||
do k=1 for words(convFrom)
|
||||
yyy=changestr(word(convFrom,k),yyy,word(convTo,k))
|
||||
end /*k*/
|
||||
call write 10,'<'tx">"yyy'</'tx">"
|
||||
end /*forever*/
|
||||
end /*j*/
|
||||
|
||||
call write 5,'<tr>'
|
||||
call write ,'</table>'
|
||||
call write ,'</html>'
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────WRITE subroutine────────────────────*/
|
||||
write: call lineout oFID,left('',0||arg(1))arg(2); return
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
/*╔══════════════════════════════╗ CHANGESTR ╔═════════════════════════╗
|
||||
╔═╩══════════════════════════════╝ function ╚═════════════════════════╩═╗
|
||||
║ new string to be used──────────┐ ┌─────limit of # changes (times)║
|
||||
║ original string (haystack)────────┐ │ │ [default: ≈ one billian]║
|
||||
║ old string to be changed───┐ │ │ │ ┌───begin at this occurance #.║
|
||||
║ {O, H, and N can be null.} │ │ │ │ │ [default: 1st occurrance]║
|
||||
╚═╦════════════════════════════╗ │ │ │ │ │ ╔═══════════════════════╦═╝
|
||||
╚════════════════════════════╝ ↓ ↓ ↓ ↓ ↓ ╚═══════════════════════╝*/
|
||||
changestr: procedure; parse arg o,h,n,t,b /* T and B are optional.*/
|
||||
$='' /*$: the returned string.*/
|
||||
t=word(t 999999999 , 1) /*maybe use the default? */
|
||||
b=word(b 1 , 1) /* " " " " */
|
||||
w=length(o) /*length of OLD string.*/
|
||||
if w==0 & t\=0 then return n || h /*changing a null char ? */
|
||||
#=0 /*# of changed occurances*/
|
||||
do j=1 until # >= t /*keep changing, T times.*/
|
||||
parse var h y (o) _ +(w) h /*parse the string ... */
|
||||
if _=='' then return $ || y /*no more left, return. */
|
||||
if j<b then $=$ || y || o /*didn't meet begin at ? */
|
||||
else do
|
||||
$=$ || y || n /*build new STR from S. */
|
||||
#=#+1 /*bump occurance number. */
|
||||
end
|
||||
end /*j*/
|
||||
/*Most REXX BIFs only ···*/
|
||||
return $ || h /* support three options.*/
|
||||
|
|
@ -3,7 +3,7 @@ func tag(t, d) { "<#{t}>#{d}</#{t}>" }
|
|||
|
||||
func csv2html(str) {
|
||||
|
||||
var template = <<'-EOT'
|
||||
var template = <<-'EOT'
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head><title>Some Text</title></head>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
csvData:=Data(0,Int,"Character,Speech\n"
|
||||
"The multitude,The messiah! Show us the messiah!\n"
|
||||
"Brians mother,<angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry>\n"
|
||||
"The multitude,Who are you\n"
|
||||
"Brians mother,I'm his mother; that's who!\n"
|
||||
"The multitude,Behold his mother! Behold his mother!");
|
||||
|
||||
html:=csvData.pump("<table>\n",fcn(line){
|
||||
line.replace("&","&").replace("<","<") // <angry/> --> <angry/>
|
||||
.split(",")
|
||||
.pump("<tr>\n","strip",String.fpM("101"," <td>","</td>\n"))+"</tr>\n"
|
||||
}) + "</table>";
|
||||
html.println();
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
<table>
|
||||
<tr>
|
||||
<td>Character</td>
|
||||
<td>Speech</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>The multitude</td>
|
||||
<td>The messiah! Show us the messiah!</td>
|
||||
</tr>
|
||||
<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>
|
||||
<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>
|
||||
</table>
|
||||
Loading…
Add table
Add a link
Reference in a new issue