From 055c0d0d5a5bb0dc75904fe53df7f2e4f5732a8f Mon Sep 17 00:00:00 2001 From: aarne Date: Wed, 21 May 2008 09:26:44 +0000 Subject: GF/src is now for 2.9, and the new sources are in src-3.0 - keep it this way until the release of GF 3 --- src-3.0/tools/Htmls.hs | 102 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 src-3.0/tools/Htmls.hs (limited to 'src-3.0/tools/Htmls.hs') diff --git a/src-3.0/tools/Htmls.hs b/src-3.0/tools/Htmls.hs new file mode 100644 index 000000000..ce0b3bb28 --- /dev/null +++ b/src-3.0/tools/Htmls.hs @@ -0,0 +1,102 @@ +---------------------------------------------------------------------- +-- | +-- Maintainer : AR +-- Stability : (stable) +-- Portability : (portable) +-- +-- > CVS $Date: 2005/05/16 17:07:18 $ +-- > CVS $Author: aarne $ +-- > CVS $Revision: 1.11 $ +-- +-- chop an HTML file into separate files, each linked to the next and previous. +-- the names of the files are n-file, with n = 01,02,... +-- the chopping is performed at each separator, here defined as @\" + +link :: FilePath -> Int -> Int -> String +link file mx n = + (if n >= mx-1 then "" else (" Next")) ++ + (if n == 1 then "" else (" Previous")) ++ + (" Contents") ++ + (" Fulltext") ++ + (" First") ++ + (" Last") + where + file_ = fileName file (n - 1) + file' = fileName file (n + 1) + file0 = fileName file 0 + file1 = fileName file 1 + file2 = fileName file (mx - 1) + +fileName :: FilePath -> Int -> FilePath +fileName file n = (if n < 10 then ('0':) else id) $ show n ++ "-" ++ file + +pageNum mx num = "

" ++ show num ++"/" ++ show (mx-1) ++ "

" + +mkIndex file = unlines . mkInd 1 where + mkInd n ss = case ss of + s : rest | (s==separator) -> mkInd (n+1) rest + s : rest -> case getHeading s of + Just (i,t) -> mkLine n i t : mkInd n rest + _ -> mkInd n rest + _ -> [] + getHeading s = case dropWhile isSpace s of + '<':h:i:_:t | isDigit i -> return (i,take (length t - 5) t) -- drop final + _ -> Nothing + mkLine _ '1' t = t ++ " : Table of Contents

" -- heading of whole document + mkLine n i t = stars i ++ link n t ++ "
" + stars i = case i of + '3' -> "

  • " + '4' -> "
  • * " + _ -> "" + link n t = "" ++ t ++ "" -- cgit v1.2.3