Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,26 @@
|
|||
--import Data.List.Split (splitOn) -- if the import is available
|
||||
splitOn :: Char -> String -> [String] -- otherwise
|
||||
splitOn delim = foldr (\x rest ->
|
||||
if x == delim then "" : rest
|
||||
else (x:head rest):tail rest) [""]
|
||||
|
||||
htmlEscape :: String -> String
|
||||
htmlEscape = concatMap escapeChar
|
||||
where escapeChar '<' = "<"
|
||||
escapeChar '>' = ">"
|
||||
escapeChar '&' = "&"
|
||||
escapeChar '"' = """ --"
|
||||
escapeChar c = [c]
|
||||
|
||||
toHtmlRow :: [String] -> String
|
||||
toHtmlRow [] = "<tr></tr>"
|
||||
toHtmlRow cols = let htmlColumns = concatMap toHtmlCol cols
|
||||
in "<tr>\n" ++ htmlColumns ++ "</tr>"
|
||||
where toHtmlCol x = " <td>" ++ htmlEscape x ++ "</td>\n"
|
||||
|
||||
csvToTable :: String -> String
|
||||
csvToTable csv = let rows = map (splitOn ',') $ lines csv
|
||||
html = unlines $ map toHtmlRow rows
|
||||
in "<table>\n" ++ html ++ "</table>"
|
||||
|
||||
main = interact csvToTable
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
import Data.List (unfoldr)
|
||||
split p = unfoldr (\s -> case dropWhile p s of [] -> Nothing
|
||||
ss -> Just $ break p ss)
|
||||
|
||||
main = interact (\csv -> "<table>\n" ++
|
||||
(unlines $ map ((\cols -> "<tr>\n" ++
|
||||
(concatMap (\x -> " <td>" ++ concatMap (\c ->
|
||||
case c of {'<' -> "<"; '>' -> ">";
|
||||
'&' -> "&"; '"' -> """; _ -> [c]}) x
|
||||
++ "</td>\n") cols)
|
||||
++ "</tr>") . split (==',')) $ lines csv) ++ "</table>")
|
||||
|
|
@ -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