1-- Create pandoc.1 man and pandoc_markdown.5 man pages from README
3import Data.ByteString.UTF8 (toString, fromString)
4import Data.Char (toUpper)
5import qualified Data.ByteString as B
8import System.Environment (getArgs)
9import Text.Pandoc.Shared (normalize)
10import System.Directory (getModificationTime)
11import System.IO.Error (isDoesNotExistError)
12import System.Time (ClockTime(..))
13import Data.Maybe (catMaybes)
16 rmContents <- liftM toString $ B.readFile "README"
17 let (Pandoc meta blocks) = readMarkdown defaultParserState rmContents
18 let manBlocks = removeSect [Str "Wrappers"]
19 $ removeSect [Str "Pandoc's",Space,Str "markdown"] blocks
20 let syntaxBlocks = extractSect [Str "Pandoc's",Space,Str "markdown"] blocks
22 let verbose = "--verbose" `elem` args
23 makeManPage verbose ("man" </> "man1" </> "pandoc.1")
25 makeManPage verbose ("man" </> "man5" </> "pandoc_markdown.5")
28makeManPage :: Bool -> FilePath -> Meta -> [Block] -> IO ()
29makeManPage verbose page meta blocks = do
30 let templ = page <.> "template"
31 modDeps <- modifiedDependencies page ["README", templ]
32 unless (null modDeps) $ do
33 manTemplate <- liftM toString $ B.readFile templ
34 writeManPage page manTemplate (Pandoc meta blocks)
36 putStrLn $ "Created " ++ page
38writeManPage :: FilePath -> String -> Pandoc -> IO ()
39writeManPage page templ doc = do
40 let opts = defaultWriterOptions{ writerStandalone = True
41 , writerTemplate = templ }
42 let manPage = writeMan opts $
43 bottomUp (concatMap removeLinks) $
44 bottomUp capitalizeHeaders doc
45 B.writeFile page $ fromString manPage
47-- | Returns a list of 'dependencies' that have been modified after 'file'.
48modifiedDependencies :: FilePath -> [FilePath] -> IO [FilePath]
49modifiedDependencies file dependencies = do
50 fileModTime <- catch (getModificationTime file) $
51 \e -> if isDoesNotExistError e
52 then return (TOD 0 0) -- the minimum ClockTime
54 depModTimes <- mapM getModificationTime dependencies
55 let modified = zipWith (\dep time -> if time > fileModTime then Just dep else Nothing) dependencies depModTimes
56 return $ catMaybes modified
58removeLinks :: Inline -> [Inline]
59removeLinks (Link l _) = l
62capitalizeHeaders :: Block -> Block
63capitalizeHeaders (Header 1 xs) = Header 1 $ bottomUp capitalize xs
64capitalizeHeaders x = x
66capitalize :: Inline -> Inline
67capitalize (Str xs) = Str $ map toUpper xs
70removeSect :: [Inline] -> [Block] -> [Block]
71removeSect ils (Header 1 x:xs) | normalize x == normalize ils =
72 dropWhile (not . isHeader1) xs
73removeSect ils (x:xs) = x : removeSect ils xs
76extractSect :: [Inline] -> [Block] -> [Block]
77extractSect ils (Header 1 z:xs) | normalize z == normalize ils =
78 bottomUp promoteHeader $ takeWhile (not . isHeader1) xs
79 where promoteHeader (Header n x) = Header (n-1) x
81extractSect ils (x:xs) = extractSect ils xs
84isHeader1 :: Block -> Bool
85isHeader1 (Header 1 _) = True
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