2015-10-26 16:56:33 +03:00
|
|
|
#!/usr/bin/env stack
|
2017-03-30 07:00:52 +03:00
|
|
|
{- stack runghc --verbosity info --package pandoc-types -}
|
2016-04-08 07:58:42 +03:00
|
|
|
-- Ensure level 1 and 2 headings are first-letter-capitalised.
|
2015-10-26 16:56:33 +03:00
|
|
|
|
2016-04-08 07:58:42 +03:00
|
|
|
import Data.Char
|
2015-10-26 16:56:33 +03:00
|
|
|
import Text.Pandoc.JSON
|
|
|
|
import Text.Pandoc.Walk
|
|
|
|
|
|
|
|
main :: IO ()
|
|
|
|
main = toJSONFilter capitalizeHeaders
|
|
|
|
|
|
|
|
capitalizeHeaders :: Block -> Block
|
2016-04-08 07:58:42 +03:00
|
|
|
capitalizeHeaders (Header lvl attr xs) | lvl < 3 = Header lvl attr $ map capitalize (take 1 xs) ++ drop 1 xs
|
2015-10-26 16:56:33 +03:00
|
|
|
capitalizeHeaders x = x
|
|
|
|
|
|
|
|
capitalize :: Inline -> Inline
|
2016-04-08 07:58:42 +03:00
|
|
|
capitalize (Str s) = Str $ map toUpper (take 1 s) ++ map toLower (drop 1 s)
|
2015-10-26 16:56:33 +03:00
|
|
|
capitalize x = x
|
|
|
|
|
|
|
|
{-
|
|
|
|
capitalizeHeaderLinks :: Inline -> Inline
|
|
|
|
capitalizeHeaderLinks (Link xs t@('#':_,_)) = Link (walk capitalize xs) t
|
|
|
|
capitalizeHeaderLinks x = x
|
|
|
|
-}
|