http://laurent.gateau.free.fr

Programmation en langage Haskell

-- fichier: www.hs --
--
-- Un programme qui ecrit un fichier html 
-- contenant le code source du programme   
-- 

import Data.Text
import Data.Time.Clock

header = 
    "<!DOCTYPE html>\n"
    ++ "<html>\n"
    ++ "<head>\n"
    ++ "    <meta charset=\"utf-8\">\n"
    ++ "    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n"
    ++ "    <title>Laurent Gateau's Haskell exercises</title>\n"
    ++ "    <base href=\"http://laurent.gateau.free.fr/\" />\n"
    ++ "    <link rel=\"stylesheet\" href=\"style.css\" type=\"text/css\" />\n"
    ++ "</head>\n"
    ++ "<body>\n"
    ++ "<div align=\"right\">\n"
    ++ "<a href=\"index.html\">http://laurent.gateau.free.fr</a>\n"
    ++ "</div>\n"


html_escape content = 
    unpack lower_escape
    where
        lower_escape = replace (pack "<") (pack "&lt;") ampersand_escape
        ampersand_escape = replace (pack "&") (pack "&amp;") (pack content)

code filecontent = 
    "<pre>\n"
    ++ (html_escape filecontent)
    ++ "</pre>\n"

h1 phrase = 
    "<h1>" ++ phrase ++ "</h1>\n"

footer now = 
    "<hr>Vous pouvez m'écrire à laurent dot gateau at free dot fr</em>\n"
    ++ "<hr>\n"
    ++ "<font size=\"-1\">Denière mise à jour: " 
    ++ now
    ++ "</font>\n"
    ++ "</body>\n"
    ++ "</html>\n"

main = do 
    putStrLn header
    putStrLn $ h1 "Programmation en langage Haskell"
    content <- readFile "www.hs"
    putStrLn (code content)
    now <- fmap show getCurrentTime
    putStrLn (footer now)

Vous pouvez m'écrire à laurent dot gateau at free dot fr
Denière mise à jour: 2021-01-24 14:18:12.67804058 UTC