From 6d99debdff614708454e899201cd6f14ec353049 Mon Sep 17 00:00:00 2001 From: aarne Date: Fri, 21 Nov 2003 13:57:49 +0000 Subject: Hew version of GFDoc. --- src/tools/Htmls.hs | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/tools/Htmls.hs (limited to 'src/tools/Htmls.hs') diff --git a/src/tools/Htmls.hs b/src/tools/Htmls.hs new file mode 100644 index 000000000..6850a38a8 --- /dev/null +++ b/src/tools/Htmls.hs @@ -0,0 +1,65 @@ +module Main where + +import System + +-- 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 "" + +-- AR 7/1/2002 for the Vinnova meeting in Linköping. + +main :: IO () +main = do + file:_ <- getArgs + htmls file + +htmls :: FilePath -> IO () +htmls file = do + s <- readFile file + let ss = allPages s + mapM (uncurry writeFile) (map (mkFile file (length ss)) ss) + return () + +allPages :: String -> [(Int,String)] +allPages = zip [1..] . map unlines . chop . lines where + chop ls = case span isNoSep ls of + (s,_:ss) -> s : chop ss + _ -> [ls] + isNoSep = (/= separator) + +mkFile :: FilePath -> Int -> (Int,String) -> (FilePath,String) +mkFile base mx (number,content) = + (fileName base number, + unlines [ + begHTML, + "", + pageNum mx number, + link base mx number, + "", + "

", + content, + endHTML + ] + ) + +begHTML, endHTML, separator :: String +begHTML = "" +endHTML = "" +separator = "" + +link :: FilePath -> Int -> Int -> String +link file mx n = + (if n >= mx then "" else (" Next")) ++ + (if n == 1 then "" else (" Previous")) ++ + (" First") ++ + (" Last") + where + file_ = fileName file (n - 1) + file' = fileName file (n + 1) + file1 = fileName file 1 + file2 = fileName file mx + +fileName :: FilePath -> Int -> FilePath +fileName file n = (if n < 10 then ('0':) else id) $ show n ++ "-" ++ file + +pageNum mx num = "

" ++ show num ++"/" ++ show mx ++ "

" -- cgit v1.2.3