1-- Create pandoc.1 man and pandoc_markdown.5 man pages from README
3import qualified Text.Pandoc.UTF8 as UTF8
4import Data.Char (toUpper)
7import System.Environment (getArgs)
8import Text.Pandoc.Shared (normalize)
9import Data.Maybe ( catMaybes )
10import Prelude hiding (catch)
11import Control.Exception ( catch )
12import System.IO.Error ( isDoesNotExistError )
13#if MIN_VERSION_directory(1,2,0)
14import Data.Time.Clock (UTCTime(..))
16import System.Time (ClockTime(..))
18import System.Directory
22 ds1 <- modifiedDependencies ("man" </> "man1" </> "pandoc.1")
23 ["README", "man" </> "man1" </> "pandoc.1.template"]
24 ds2 <- modifiedDependencies ("man" </> "man5" </> "pandoc_markdown.5")
25 ["README", "man" </> "man5" </> "pandoc_markdown.5.template"]
27 unless (null ds1 && null ds2) $ do
28 rmContents <- UTF8.readFile "README"
29 let (Pandoc meta blocks) = readMarkdown def rmContents
30 let manBlocks = removeSect [Str "Wrappers"]
31 $ removeSect [Str "Pandoc's",Space,Str "markdown"] blocks
32 let syntaxBlocks = extractSect [Str "Pandoc's",Space,Str "markdown"] blocks
34 let verbose = "--verbose" `elem` args
36 makeManPage verbose ("man" </> "man1" </> "pandoc.1") meta manBlocks
38 makeManPage verbose ("man" </> "man5" </> "pandoc_markdown.5") meta syntaxBlocks
40makeManPage :: Bool -> FilePath -> Meta -> [Block] -> IO ()
41makeManPage verbose page meta blocks = do
42 let templ = page <.> "template"
43 manTemplate <- UTF8.readFile templ
44 writeManPage page manTemplate (Pandoc meta blocks)
45 when verbose $ putStrLn $ "Created " ++ page
47writeManPage :: FilePath -> String -> Pandoc -> IO ()
48writeManPage page templ doc = do
49 let opts = def{ writerStandalone = True
50 , writerTemplate = templ }
51 let manPage = writeMan opts $
52 bottomUp (concatMap removeLinks) $
53 bottomUp capitalizeHeaders doc
54 UTF8.writeFile page manPage
56removeLinks :: Inline -> [Inline]
57removeLinks (Link l _) = l
60capitalizeHeaders :: Block -> Block
61capitalizeHeaders (Header 1 attr xs) = Header 1 attr $ bottomUp capitalize xs
62capitalizeHeaders x = x
64capitalize :: Inline -> Inline
65capitalize (Str xs) = Str $ map toUpper xs
68removeSect :: [Inline] -> [Block] -> [Block]
69removeSect ils (Header 1 _ x:xs) | normalize x == normalize ils =
70 dropWhile (not . isHeader1) xs
71removeSect ils (x:xs) = x : removeSect ils xs
74extractSect :: [Inline] -> [Block] -> [Block]
75extractSect ils (Header 1 _ z:xs) | normalize z == normalize ils =
76 bottomUp promoteHeader $ takeWhile (not . isHeader1) xs
77 where promoteHeader (Header n attr x) = Header (n-1) attr x
79extractSect ils (x:xs) = extractSect ils xs
82isHeader1 :: Block -> Bool
83isHeader1 (Header 1 _ _ ) = True
87-- | Returns a list of 'dependencies' that have been modified after 'file'.
88modifiedDependencies :: FilePath -> [FilePath] -> IO [FilePath]
89modifiedDependencies file dependencies = do
90 fileModTime <- catch (getModificationTime file) $
91 \e -> if isDoesNotExistError e
92#if MIN_VERSION_directory(1,2,0)
93 then return (UTCTime (toEnum 0) 0) -- the minimum ClockTime
95 then return (TOD 0 0) -- the minimum ClockTime
98 depModTimes <- mapM getModificationTime dependencies
99 let modified = zipWith (\dep time -> if time > fileModTime then Just dep else Nothing) dependencies depModTimes
100 return $ catMaybes modified
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list