@@ -1,101 +0,0 @@
1−{-# LANGUAGE CPP #-}
2−{-
3−Copyright (C) 2013-2015 John MacFarlane <jgm@berkeley.edu>
4−
5−This program is free software; you can redistribute it and/or modify
6−it under the terms of the GNU General Public License as published by
7−the Free Software Foundation; either version 2 of the License, or
8−(at your option) any later version.
9−
10−This program is distributed in the hope that it will be useful,
11−but WITHOUT ANY WARRANTY; without even the implied warranty of
12−MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13−GNU General Public License for more details.
14−
15−You should have received a copy of the GNU General Public License
16−along with this program; if not, write to the Free Software
17−Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18−-}
19−
20−{- |
21− Module : Text.Pandoc.ManPages
22− Copyright : Copyright (C) 2013-2015 John MacFarlane
23− License : GNU GPL, version 2 or above
24−
25− Maintainer : John MacFarlane <jgm@berkeley.edu>
26− Stability : alpha
27− Portability : portable
28−
29−Functions to build pandoc's man pages (pandoc.1 and pandoc_markdown.5)
30−from pandoc's README.
31−-}
32−module Text.Pandoc.ManPages (
33− manPandoc1,
34− manPandocMarkdown5
35− ) where
36−import Text.Pandoc
37−import Text.Pandoc.Error (handleError)
38−import Data.Char (toUpper)
39−import System.FilePath
40−import Text.Pandoc.Shared (normalize, readDataFileUTF8)
41−
42−manPandoc1 :: IO String
43−manPandoc1 = do
44− readme <- readDataFileUTF8 Nothing "README"
45− let (Pandoc meta blocks) = normalize $ handleError
46− $ readMarkdown def readme
47− let manBlocks = removeSect [Str "Wrappers"]
48− $ removeSect [Str "Pandoc's",Space,Str "markdown"] blocks
49− makeManPage "pandoc.1" meta manBlocks
50−
51−manPandocMarkdown5 :: IO String
52−manPandocMarkdown5 = do
53− readme <- readDataFileUTF8 Nothing "README"
54− let (Pandoc meta blocks) = normalize $ handleError
55− $ readMarkdown def readme
56− let syntaxBlocks = extractSect [Str "Pandoc's",Space,Str "markdown"] blocks
57− makeManPage "pandoc_markdown.5" meta syntaxBlocks
58−
59−makeManPage :: String -> Meta -> [Block] -> IO String
60−makeManPage page meta blocks = do
61− let templ = page <.> "template"
62− manTemplate <- readDataFileUTF8 Nothing templ
63− return $ writeManPage manTemplate (Pandoc meta blocks)
64−
65−writeManPage :: String -> Pandoc -> String
66−writeManPage templ doc =
67− writeMan def{ writerStandalone = True
68− , writerTemplate = templ
69− , writerVariables = [("version", pandocVersion)] } $
70− bottomUp (concatMap removeLinks) $
71− bottomUp capitalizeHeaders doc
72−
73−removeLinks :: Inline -> [Inline]
74−removeLinks (Link l _) = l
75−removeLinks x = [x]
76−
77−capitalizeHeaders :: Block -> Block
78−capitalizeHeaders (Header 1 attr xs) = Header 1 attr $ bottomUp capitalize xs
79−capitalizeHeaders x = x
80−
81−capitalize :: Inline -> Inline
82−capitalize (Str xs) = Str $ map toUpper xs
83−capitalize x = x
84−
85−removeSect :: [Inline] -> [Block] -> [Block]
86−removeSect ils (Header 1 _ x:xs) | x == ils =
87− dropWhile (not . isHeader1) xs
88−removeSect ils (x:xs) = x : removeSect ils xs
89−removeSect _ [] = []
90−
91−extractSect :: [Inline] -> [Block] -> [Block]
92−extractSect ils (Header 1 _ z:xs) | z == ils =
93− bottomUp promoteHeader $ takeWhile (not . isHeader1) xs
94− where promoteHeader (Header n attr x) = Header (n-1) attr x
95− promoteHeader x = x
96−extractSect ils (_:xs) = extractSect ils xs
97−extractSect _ [] = []
98−
99−isHeader1 :: Block -> Bool
100−isHeader1 (Header 1 _ _ ) = True
101−isHeader1 _ = False