New method for building man pages.

+ Removed `--man1`, `--man5` options (breaking change).
+ Removed `Text.Pandoc.ManPages` module (breaking API change).
+ Version bump to 1.15 because of the breaking changes, even
  though they involve features that have only been in pandoc
  for a day.
+ Makefile target for `man/man1/pandoc.1`.  This uses pandoc to
  create the man page from README using a custom template and filters.
+ Added `man/` directory with template and filters needed to build
  man page.
+ We no longer have two man pages: pandoc.1 and pandoc_markdown.5.
  Now there is just pandoc.1, which has all the content from README.
  This change was needed because of the extensive cross-references
  between parts of the README.
+ Removed old `data/pandoc.1.template` and
  `data/pandoc_markdown.5.template`.
This commit is contained in:
John MacFarlane 2015-07-01 11:21:34 -07:00
parent 6862aa2687
commit a04c15a422
11 changed files with 53 additions and 162 deletions

View file

@ -75,11 +75,9 @@ Quick install
--extra-include-dirs=/usr/local/Cellar/icu4c/51.1/include \
-funicode_collation text-icu pandoc-citeproc
To build the `pandoc.1` and `pandoc_markdown.5` man pages, you
can ues pandoc itself:
To build the `pandoc.1` man page:
pandoc --man1 > pandoc.1
pandoc --man5 > pandoc_markdown.5
make man/man1/pandoc.1
To build the `pandoc-citeproc` man pages, go to the pandoc-citeproc
build directory, and

View file

@ -1,18 +1,17 @@
version=$(shell grep '^Version:' pandoc.cabal | awk '{print $$2;}')
setup=dist/setup/setup
PREFIX ?= /usr/local
pandoc=$(shell find dist -name pandoc -type f -exec ls -t {} \; | head -1)
quick:
cabal configure --enable-tests --disable-optimization
cabal build
full:
cabal configure --enable-tests --enable-optimization -ftrypandoc -fmake-pandoc-man-pages -fembed_data_files --enable-benchmarks
cabal configure --enable-tests --enable-optimization -ftrypandoc -fembed_data_files --enable-benchmarks
cabal build
cabal haddock
deps:
cabal install --only-dependencies --enable-tests -ftrypandoc -fmake-pandoc-man-pages -fembed_data_files --enable-benchmarks
cabal install --only-dependencies --enable-tests -ftrypandoc -fembed_data_files --enable-benchmarks
prof:
cabal configure --enable-library-profiling --enable-executable-profiling --enable-optimization --enable-tests
@ -28,7 +27,7 @@ install: full
cabal copy
cabal register
dist: man
dist:
cabal sdist
rm -rf "pandoc-${version}"
tar xvzf dist/pandoc-${version}.tar.gz
@ -41,11 +40,14 @@ debpkg:
osxpkg:
./make_osx_package.sh
%.1: %.1.template README
${makemanpages}
%.5: %.5.template README
${makemanpages}
man/man1/pandoc.1: README man/pandoc.1.template
@[ -n "$(pandoc)" ] || \
(echo "Could not find pandoc in dist/" && exit 1)
$(pandoc) $< -t man -s --template man/pandoc.1.template \
--filter man/capitalizeHeaders.hs \
--filter man/removeNotes.hs \
--filter man/removeLinks.hs \
-o $@
download_stats:
curl https://api.github.com/repos/jgm/pandoc/releases | \
@ -53,6 +55,6 @@ download_stats:
clean:
cabal clean
-rm -rf $(BINDIST) $(BINDIST).tar.gz
-rm man/man1/pandoc.1
.PHONY: deps quick full install man clean test bench haddock osxpkg dist bindist prof download_stats

8
README
View file

@ -240,14 +240,6 @@ General options
`epub.css`, `templates`, `slidy`, `slideous`, or `s5` directory
placed in this directory will override pandoc's normal defaults.
`--man1`
: Write `pandoc.1` man page to *stdout*.
`--man5`
: Write `pandoc_markdown.5` man page to *stdout*.
`--verbose`
: Give verbose debugging output. Currently this only has an effect

View file

@ -1,11 +0,0 @@
$if(has-tables)$
.\"t
$endif$
.TH PANDOC_MARKDOWN 5 "$date$" "$version$"
.SH NAME
pandoc_markdown - markdown syntax for pandoc(1)
.SH DESCRIPTION
$body$
.SH SEE ALSO
.PP
\f[C]pandoc\f[] (1).

18
man/capitalizeHeaders.hs Normal file
View file

@ -0,0 +1,18 @@
import Text.Pandoc.JSON
import Text.Pandoc.Walk
import Data.Char (toUpper)
main :: IO ()
main = toJSONFilter capitalizeHeaders
capitalizeHeaders :: Block -> Block
capitalizeHeaders (Header 1 attr xs) = Header 1 attr $ walk capitalize xs
capitalizeHeaders x = walk capitalizeHeaderLinks x
capitalize :: Inline -> Inline
capitalize (Str xs) = Str $ map toUpper xs
capitalize x = x
capitalizeHeaderLinks :: Inline -> Inline
capitalizeHeaderLinks (Link xs t@('#':_,_)) = Link (walk capitalize xs) t
capitalizeHeaderLinks x = x

View file

@ -5,12 +5,6 @@ $endif$
.SH NAME
pandoc - general markup converter
$body$
.SH PANDOC'S MARKDOWN
For a complete description of pandoc's extensions to standard markdown,
see \f[C]pandoc_markdown\f[] (5).
.SH SEE ALSO
.PP
\f[C]pandoc_markdown\f[] (5).
.PP
The Pandoc source code and all documentation may be downloaded
from <http://pandoc.org>.

9
man/removeLinks.hs Normal file
View file

@ -0,0 +1,9 @@
import Text.Pandoc.JSON
main :: IO ()
main = toJSONFilter removeLinks
removeLinks :: Inline -> [Inline]
removeLinks (Link l _) = l
removeLinks x = [x]

9
man/removeNotes.hs Normal file
View file

@ -0,0 +1,9 @@
import Text.Pandoc.JSON
main :: IO ()
main = toJSONFilter removeNotes
removeNotes :: Inline -> Inline
removeNotes (Note _) = Str ""
removeNotes x = x

View file

@ -1,5 +1,5 @@
Name: pandoc
Version: 1.14.1
Version: 1.15
Cabal-Version: >= 1.10
Build-Type: Custom
License: GPL
@ -106,9 +106,6 @@ Data-Files:
data/sample.lua
-- documentation
README, COPYRIGHT
-- man page templates
data/pandoc.1.template
data/pandoc_markdown.5.template
Extra-Source-Files:
-- documentation
INSTALL, BUGS, CONTRIBUTING.md, changelog
@ -355,8 +352,7 @@ Library
Text.Pandoc.Templates,
Text.Pandoc.XML,
Text.Pandoc.SelfContained,
Text.Pandoc.Process,
Text.Pandoc.ManPages
Text.Pandoc.Process
Other-Modules: Text.Pandoc.Readers.Docx.Lists,
Text.Pandoc.Readers.Docx.Reducible,
Text.Pandoc.Readers.Docx.Parse,

View file

@ -39,7 +39,6 @@ import Text.Pandoc.Shared ( tabFilter, readDataFileUTF8, readDataFile,
safeRead, headerShift, normalize, err, warn,
openURL )
import Text.Pandoc.MediaBag ( mediaDirectory, extractMediaBag, MediaBag )
import Text.Pandoc.ManPages ( manPandoc1, manPandocMarkdown5 )
import Text.Pandoc.XML ( toEntities )
import Text.Pandoc.SelfContained ( makeSelfContained )
import Text.Pandoc.Process (pipeProcess)
@ -870,20 +869,6 @@ options =
(\opt -> return opt { optIgnoreArgs = True }))
"" -- "Ignore command-line arguments."
, Option "" ["man1"]
(NoArg
(\_ -> do
manPandoc1 >>= UTF8.hPutStr stdout
exitWith ExitSuccess ))
"" -- "Print pandoc.1 man page"
, Option "" ["man5"]
(NoArg
(\_ -> do
manPandocMarkdown5 >>= UTF8.hPutStr stdout
exitWith ExitSuccess ))
"" -- "Print pandoc_markdown.5 man page"
, Option "" ["verbose"]
(NoArg
(\opt -> return opt { optVerbose = True }))

View file

@ -1,101 +0,0 @@
{-# LANGUAGE CPP #-}
{-
Copyright (C) 2013-2015 John MacFarlane <jgm@berkeley.edu>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-}
{- |
Module : Text.Pandoc.ManPages
Copyright : Copyright (C) 2013-2015 John MacFarlane
License : GNU GPL, version 2 or above
Maintainer : John MacFarlane <jgm@berkeley.edu>
Stability : alpha
Portability : portable
Functions to build pandoc's man pages (pandoc.1 and pandoc_markdown.5)
from pandoc's README.
-}
module Text.Pandoc.ManPages (
manPandoc1,
manPandocMarkdown5
) where
import Text.Pandoc
import Text.Pandoc.Error (handleError)
import Data.Char (toUpper)
import System.FilePath
import Text.Pandoc.Shared (normalize, readDataFileUTF8)
manPandoc1 :: IO String
manPandoc1 = do
readme <- readDataFileUTF8 Nothing "README"
let (Pandoc meta blocks) = normalize $ handleError
$ readMarkdown def readme
let manBlocks = removeSect [Str "Wrappers"]
$ removeSect [Str "Pandoc's",Space,Str "markdown"] blocks
makeManPage "pandoc.1" meta manBlocks
manPandocMarkdown5 :: IO String
manPandocMarkdown5 = do
readme <- readDataFileUTF8 Nothing "README"
let (Pandoc meta blocks) = normalize $ handleError
$ readMarkdown def readme
let syntaxBlocks = extractSect [Str "Pandoc's",Space,Str "markdown"] blocks
makeManPage "pandoc_markdown.5" meta syntaxBlocks
makeManPage :: String -> Meta -> [Block] -> IO String
makeManPage page meta blocks = do
let templ = page <.> "template"
manTemplate <- readDataFileUTF8 Nothing templ
return $ writeManPage manTemplate (Pandoc meta blocks)
writeManPage :: String -> Pandoc -> String
writeManPage templ doc =
writeMan def{ writerStandalone = True
, writerTemplate = templ
, writerVariables = [("version", pandocVersion)] } $
bottomUp (concatMap removeLinks) $
bottomUp capitalizeHeaders doc
removeLinks :: Inline -> [Inline]
removeLinks (Link l _) = l
removeLinks x = [x]
capitalizeHeaders :: Block -> Block
capitalizeHeaders (Header 1 attr xs) = Header 1 attr $ bottomUp capitalize xs
capitalizeHeaders x = x
capitalize :: Inline -> Inline
capitalize (Str xs) = Str $ map toUpper xs
capitalize x = x
removeSect :: [Inline] -> [Block] -> [Block]
removeSect ils (Header 1 _ x:xs) | x == ils =
dropWhile (not . isHeader1) xs
removeSect ils (x:xs) = x : removeSect ils xs
removeSect _ [] = []
extractSect :: [Inline] -> [Block] -> [Block]
extractSect ils (Header 1 _ z:xs) | z == ils =
bottomUp promoteHeader $ takeWhile (not . isHeader1) xs
where promoteHeader (Header n attr x) = Header (n-1) attr x
promoteHeader x = x
extractSect ils (_:xs) = extractSect ils xs
extractSect _ [] = []
isHeader1 :: Block -> Bool
isHeader1 (Header 1 _ _ ) = True
isHeader1 _ = False