{- | Module : $Header$ Description : Generating HTML documentation Copyright : (c) 2011 - 2016, Björn Peemöller 2016 , Jan Tikovsky License : BSD-3-clause Maintainer : bjp@informatik.uni-kiel.de Stability : experimental Portability : portable This module defines a function for generating HTML documentation pages for Curry source modules. -} {-# LANGUAGE TemplateHaskell #-} module Html.CurryHtml (source2html) where import Prelude as P import Control.Monad.Writer import Data.List (mapAccumL) import Data.Maybe (fromMaybe, isJust) import Data.ByteString as BS (ByteString, writeFile) import Data.FileEmbed import Network.URI (escapeURIString, isUnreserved) import System.FilePath ((>)) import Curry.Base.Ident ( ModuleIdent (..), Ident (..), QualIdent (..) , unqualify, moduleName) import Curry.Base.Monad (CYIO) import Curry.Base.Position (Position) import Curry.Files.Filenames (htmlName) import Curry.Syntax (Module (..), Token) import Html.SyntaxColoring import CompilerOpts (Options (..)) -- |Read file via TemplateHaskell at compile time cssContent :: ByteString cssContent = $(makeRelativeToProject "data/currysource.css" >>= embedFile) -- | Name of the css file -- NOTE: The relative path is given above cssFileName :: String cssFileName = "currysource.css" -- |Translate source file into HTML file with syntaxcoloring source2html :: Options -> ModuleIdent -> [(Position, Token)] -> Module a -> CYIO () source2html opts mid toks mdl = do liftIO $ P.writeFile (outDir > htmlName mid) doc updateCSSFile outDir where doc = program2html mid (genProgram mdl toks) outDir = fromMaybe "." (optHtmlDir opts) -- |Update the CSS file updateCSSFile :: FilePath -> CYIO () updateCSSFile dir = do let target = dir > cssFileName liftIO $ BS.writeFile target cssContent -- generates htmlcode with syntax highlighting -- @param modulname -- @param a program -- @return HTMLcode program2html :: ModuleIdent -> [Code] -> String program2html m codes = unlines [ "" , "" , "
" , "" , "" , "" ++ lineHtml ++ " | "
, "" ++ codeHtml ++ " | "
, "