{- | 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. -} module Html.CurryHtml (source2html) where import Control.Monad.Writer import Data.List (mapAccumL) import Data.Maybe (fromMaybe, isJust) import Network.URI (escapeURIString, isUnreserved) import System.Directory (copyFile, doesFileExist) import System.FilePath ((>)) import Curry.Base.Ident ( ModuleIdent (..), Ident (..), QualIdent (..) , unqualify, moduleName) import Curry.Base.Monad (CYIO, failMessages) import Curry.Base.Position (Position) import Curry.Base.Pretty ((<+>), text, vcat) import Curry.Files.Filenames (htmlName) import Curry.Syntax (Module (..), Token) import Html.SyntaxColoring import Base.Messages (message) import CompilerOpts (Options (..)) import Paths_curry_frontend (getDataFileName) -- |'FilePath' of the CSS style file to be added to the documentation. cssFile :: FilePath cssFile = "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 $ 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 src <- liftIO $ getDataFileName cssFile let target = dir > cssFile srcExists <- liftIO $ doesFileExist src if srcExists then liftIO $ copyFile src target else failMessages [message $ missingStyleFile src] where missingStyleFile f = vcat [ text "Could not copy CSS style file:" , text "File" <+> text ("`" ++ f ++ "'") <+> text "does not exist" ] -- generates htmlcode with syntax highlighting -- @param modulname -- @param a program -- @return HTMLcode program2html :: ModuleIdent -> [Code] -> String program2html m codes = unlines [ "" , "", "
" , "" , "" ++ lineHtml ++ " | "
, "" ++ codeHtml ++ " | "
, "