Skip to content

Instantly share code, notes, and snippets.

@jgm
Created January 17, 2011 00:35
Show Gist options
  • Save jgm/782307 to your computer and use it in GitHub Desktop.
Save jgm/782307 to your computer and use it in GitHub Desktop.
revised version to help find problem with MacPorts install...
-- Create pandoc.1 man page from README
import Text.Pandoc
import Data.ByteString.UTF8 (toString, fromString)
import Data.Char (toUpper)
import qualified Data.ByteString as B
import Control.Monad
import System.FilePath
main = do
rmContents <- liftM toString $ B.readFile "README"
let (Pandoc meta blocks) = readMarkdown defaultParserState rmContents
let newBlocks = removeWrapperSect blocks
manTemplate <- liftM toString $ B.readFile "manpage.template"
let opts = defaultWriterOptions{ writerStandalone = True
, writerTemplate = manTemplate }
let manPage = writeMan opts $
bottomUp (concatMap removeLinks) $
bottomUp capitalizeHeaders $
Pandoc meta newBlocks
print manPage
return ()
-- B.writeFile ("man" </> "man1" </> "pandoc.1") $ fromString manPage
removeLinks :: Inline -> [Inline]
removeLinks (Link l _) = l
removeLinks x = [x]
capitalizeHeaders :: Block -> Block
capitalizeHeaders (Header 1 xs) = Header 1 $ bottomUp capitalize xs
capitalizeHeaders x = x
capitalize :: Inline -> Inline
capitalize (Str xs) = Str $ map toUpper xs
capitalize x = x
removeWrapperSect :: [Block] -> [Block]
removeWrapperSect (Header 1 [Str "Wrappers"]:xs) =
dropWhile notLevelOneHeader xs
where notLevelOneHeader (Header 1 _) = False
notLevelOneHeader _ = True
removeWrapperSect (x:xs) = x : removeWrapperSect xs
removeWrapperSect [] = []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment