diff options
| author | hallgren <hallgren@chalmers.se> | 2012-10-23 12:55:32 +0000 |
|---|---|---|
| committer | hallgren <hallgren@chalmers.se> | 2012-10-23 12:55:32 +0000 |
| commit | f273c643b56bf0ad285cf32407906dca380909a0 (patch) | |
| tree | d5d6865a688b9f627d43c33e8ccb620c616171bd /examples/fracas/ToHTML.hs | |
| parent | bb93e18ec17a49be1c91d0890d1eb8b21d854950 (diff) | |
fracas: code to generate HTML treebank
Diffstat (limited to 'examples/fracas/ToHTML.hs')
| -rw-r--r-- | examples/fracas/ToHTML.hs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/examples/fracas/ToHTML.hs b/examples/fracas/ToHTML.hs new file mode 100644 index 000000000..4eccfdcfe --- /dev/null +++ b/examples/fracas/ToHTML.hs @@ -0,0 +1,43 @@ +import Data.Char(isSpace) + +main = interact (unlines.wrap "dl".concatMap conv.paras.lines) + +conv (('@':n):ls) = (tag_class aname "dt"++(fmtnum n++": "++vt abs++" "++abs)):map conc concs + where + (aname,abs):concs = map (apSnd (dropWhile isSpace.drop 1).break (==':')) ls + conc (lang,s) = tag_class lang "dd"++vp abs lang++" "++s + +vt abs = tag' "img" ("src=\"http://cloud.grammaticalframework.org/minibar/tree-btn.png\""++a) + where + a = " onclick=\"vt(this,'"++abs++"')\"" + +vp abs lang = tag' "img" ("src=\"http://cloud.grammaticalframework.org/minibar/tree-btn.png\""++a) + where + a = " onclick=\"vp(this,'"++lang++"','"++abs++"')\"" + +fmtnum n = + case words (map u2s n) of + [_,n1,n2,_] -> dropWhile (=='0') n1++"."++n2 + _ -> n + where + u2s '_' = ' ' + u2s c = c + +-------------------------------------------------------------------------------- + +paras ls = + case dropWhile null ls of + [] -> [] + ls -> case break null ls of + (ls1,ls2) -> ls1:paras ls2 + +wrap t ls = tag t:ls++[endtag t] + +tag_class cls t = tag' t ("class="++cls) + +tag' t a = '<':t++" "++a++">" + +tag t = '<':t++">" +endtag t = tag ('/':t) + +apSnd f (x,y) = (x,f y) |
