doc: improve new combined manual, cleanups

This commit is contained in:
Simon Michael 2016-04-07 21:58:42 -07:00
parent 0982aca223
commit 33e2ca927f
3 changed files with 34 additions and 12 deletions

View File

@ -118,13 +118,13 @@ main = do
let md = out <.> "md" let md = out <.> "md"
tmpl = "doc/manpage.nroff" tmpl = "doc/manpage.nroff"
need $ md : tmpl : pandocFilters need $ md : tmpl : pandocFilters
cmd pandoc md "-s --template" tmpl "-o" out cmd pandoc md "-s --template" tmpl
"--filter doc/pandoc-drop-web-blocks" "--filter doc/pandoc-drop-web-blocks"
"--filter doc/pandoc-drop-html-blocks" "--filter doc/pandoc-drop-html-blocks"
"--filter doc/pandoc-drop-html-inlines" "--filter doc/pandoc-drop-html-inlines"
"--filter doc/pandoc-drop-links" "--filter doc/pandoc-drop-links"
"--filter doc/pandoc-drop-notes" "--filter doc/pandoc-drop-notes"
"--filter doc/pandoc-capitalize-headers" "-o" out
-- man pages adjusted for web by pandoc (ready for hakyll) -- man pages adjusted for web by pandoc (ready for hakyll)
let webManpageMds = ["site" </> p <.>".md" | p <- manpages] let webManpageMds = ["site" </> p <.>".md" | p <- manpages]
@ -133,10 +133,11 @@ main = do
let p = dropExtension $ takeFileName out let p = dropExtension $ takeFileName out
md = manpageDir p </> p <.> "md" md = manpageDir p </> p <.> "md"
need $ md : pandocFilters need $ md : pandocFilters
cmd pandoc md "-o" out cmd pandoc md
"--filter doc/pandoc-demote-headers" "--filter doc/pandoc-demote-headers"
-- "--filter doc/pandoc-add-toc" -- "--filter doc/pandoc-add-toc"
-- "--filter doc/pandoc-drop-man-blocks" -- "--filter doc/pandoc-drop-man-blocks"
"-o" out
-- method 2: -- method 2:
@ -151,12 +152,12 @@ main = do
tmpl = "doc/manpage.nroff" tmpl = "doc/manpage.nroff"
need $ m4src : m4lib : tmpl : pandocFilters ++ m4includes need $ m4src : m4lib : tmpl : pandocFilters ++ m4includes
cmd Shell "m4 -P" "-DMAN" "-I" dir m4lib m4src cmd Shell "m4 -P" "-DMAN" "-I" dir m4lib m4src
"|" pandoc "-s --template" tmpl "-o" out "|" pandoc "-s --template" tmpl
"--filter doc/pandoc-drop-html-blocks" "--filter doc/pandoc-drop-html-blocks"
"--filter doc/pandoc-drop-html-inlines" "--filter doc/pandoc-drop-html-inlines"
"--filter doc/pandoc-drop-links" "--filter doc/pandoc-drop-links"
"--filter doc/pandoc-drop-notes" "--filter doc/pandoc-drop-notes"
"--filter doc/pandoc-capitalize-headers" "-o" out
-- man pages assembled from parts and adjusted for web with m4, adjusted slightly more with pandoc (ready for hakyll) -- man pages assembled from parts and adjusted for web with m4, adjusted slightly more with pandoc (ready for hakyll)
let m4webManpageMds = ["site" </> "m4-"++p <.>".md" | p <- ["hledger.1"]] let m4webManpageMds = ["site" </> "m4-"++p <.>".md" | p <- ["hledger.1"]]
@ -170,9 +171,10 @@ main = do
m4lib = "doc/lib.m4" m4lib = "doc/lib.m4"
need $ m4src : m4lib : m4includes need $ m4src : m4lib : m4includes
cmd Shell "m4 -P" "-DMAN -DWEB" "-I" dir m4lib m4src cmd Shell "m4 -P" "-DMAN -DWEB" "-I" dir m4lib m4src
"|" pandoc "-o" out "|" pandoc
"--filter doc/pandoc-demote-headers" "--filter doc/pandoc-demote-headers"
-- "--filter doc/pandoc-add-toc" -- "--filter doc/pandoc-add-toc"
"-o" out
-- web manual combined from man pages -- web manual combined from man pages
@ -180,12 +182,30 @@ main = do
phony "webmanual" $ need [ webmanual ] phony "webmanual" $ need [ webmanual ]
"site/manual2.md" %> \out -> do "site/manual2.md" %> \out -> do
need webManpageMds need webManpageMds
cmd Shell "printf '* toc\\n\\n' >" webmanual :: Action ExitCode liftIO $ writeFile webmanual [i|
<style>
#toc > ol > li {
padding-top:1em;
font-weight:bold;
}
#toc > ol > li > ol {
font-weight:normal;
}
</style>
* toc
|]
forM_ webManpageMds $ \f -> do forM_ webManpageMds $ \f -> do
let manpage = dropExtension $ takeFileName f let heading =
cmd Shell ("printf '\\n## "++ manpage ++"\\n\\n' >>") webmanual :: Action ExitCode let s = dropExtension $ dropExtension $ takeFileName f
in if "hledger_" `isPrefixOf` s
then drop 8 s ++ " format"
else s
cmd Shell ("printf '\\n## "++ heading ++"\\n\\n' >>") webmanual :: Action ExitCode
cmd Shell "pandoc" f "-t markdown" cmd Shell "pandoc" f "-t markdown"
"--filter doc/pandoc-drop-man-blocks"
"--filter doc/pandoc-drop-toc" "--filter doc/pandoc-drop-toc"
-- "--filter doc/pandoc-capitalize-headers"
"--filter doc/pandoc-demote-headers" "--filter doc/pandoc-demote-headers"
">>" webmanual :: Action ExitCode ">>" webmanual :: Action ExitCode

1
doc/.gitignore vendored
View File

@ -1,5 +1,6 @@
pandoc-add-toc pandoc-add-toc
pandoc-capitalize-headers pandoc-capitalize-headers
pandoc-demote-headers
pandoc-drop-html-blocks pandoc-drop-html-blocks
pandoc-drop-html-inlines pandoc-drop-html-inlines
pandoc-drop-links pandoc-drop-links

View File

@ -1,19 +1,20 @@
#!/usr/bin/env stack #!/usr/bin/env stack
{- stack runghc --verbosity info --package pandoc-types-1.16.1 -} {- stack runghc --verbosity info --package pandoc-types-1.16.1 -}
-- Ensure level 1 and 2 headings are first-letter-capitalised.
import Data.Char
import Text.Pandoc.JSON import Text.Pandoc.JSON
import Text.Pandoc.Walk import Text.Pandoc.Walk
import Data.Char (toUpper)
main :: IO () main :: IO ()
main = toJSONFilter capitalizeHeaders main = toJSONFilter capitalizeHeaders
capitalizeHeaders :: Block -> Block capitalizeHeaders :: Block -> Block
capitalizeHeaders (Header 1 attr xs) = Header 1 attr $ walk capitalize xs capitalizeHeaders (Header lvl attr xs) | lvl < 3 = Header lvl attr $ map capitalize (take 1 xs) ++ drop 1 xs
capitalizeHeaders x = x capitalizeHeaders x = x
capitalize :: Inline -> Inline capitalize :: Inline -> Inline
capitalize (Str xs) = Str $ map toUpper xs capitalize (Str s) = Str $ map toUpper (take 1 s) ++ map toLower (drop 1 s)
capitalize x = x capitalize x = x
{- {-