git.iko.soy/typeable/pandoc
on master help sign in
Added --chapters option affecting docbook and latex.

* Added writerChapters to WriterOptions. * Added --chapters command-line option. * --chapters causes top-level headers to be "chapter" instead of "section" in LaTeX and DocBook. * Resolves Issue #225.

commit9721b87c26861fd9495cd0697fe79c6b1b5e6211 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 16 Jan 2011, 08:57 (16 years ago) parent53eb2c4
4 files changed+18−4
src/Text/Pandoc/Shared.hs+2 src/Text/Pandoc/Writers/Docbook.hs+5−2 src/Text/Pandoc/Writers/LaTeX.hs+1−1 src/pandoc.hs+10−1
src/Text/Pandoc/Shared.hs+2
@@ -482,6 +482,7 @@ data WriterOptions = WriterOptions
482482 , writerCiteMethod :: CiteMethod -- ^ How to print cites
483483 , writerBiblioFiles :: [FilePath] -- ^ Biblio files to use for citations
484484 , writerHtml5 :: Bool -- ^ Produce HTML5
485+ , writerChapters :: Bool -- ^ Use "chapter" for top-level sects
485486 } deriving Show
486487
487488-- | Default writer options.
@@ -512,6 +513,7 @@ defaultWriterOptions =
512513 , writerCiteMethod = Citeproc
513514 , writerBiblioFiles = []
514515 , writerHtml5 = False
516+ , writerChapters = False
515517 }
516518
517519--
src/Text/Pandoc/Writers/Docbook.hs+5−2
@@ -87,9 +87,12 @@ elementToDocbook opts (Sec _ _num id' title elements) =
8787 let elements' = if null elements
8888 then [Blk (Para [])]
8989 else elements
90− in inTags True "section" [("id",id')] $
90+ tag = if writerChapters opts
91+ then "chapter"
92+ else "section"
93+ in inTags True tag [("id",id')] $
9194 inTagsSimple "title" (inlinesToDocbook opts title) $$
92− vcat (map (elementToDocbook opts) elements')
95+ vcat (map (elementToDocbook opts{ writerChapters = False }) elements')
9396
9497-- | Convert a list of Pandoc blocks to Docbook.
9598blocksToDocbook :: WriterOptions -> [Block] -> Doc
src/Text/Pandoc/Writers/LaTeX.hs+1−1
@@ -63,7 +63,7 @@ writeLaTeX options document =
6363 stVerbInNote = False, stEnumerate = False,
6464 stTable = False, stStrikeout = False, stSubscript = False,
6565 stUrl = False, stGraphics = False,
66− stLHS = False, stBook = False }
66+ stLHS = False, stBook = writerChapters options }
6767
6868pandocToLaTeX :: WriterOptions -> Pandoc -> State WriterState String
6969pandocToLaTeX options (Pandoc (Meta title authors date) blocks) = do
src/pandoc.hs+10−1
@@ -103,6 +103,7 @@ data Opt = Opt
103103 , optXeTeX :: Bool -- ^ Format latex for xetex
104104 , optSmart :: Bool -- ^ Use smart typography
105105 , optHtml5 :: Bool -- ^ Produce HTML5 in HTML
106+ , optChapters :: Bool -- ^ Use chapter for top-level sects
106107 , optHTMLMathMethod :: HTMLMathMethod -- ^ Method to print HTML math
107108 , optReferenceODT :: Maybe FilePath -- ^ Path of reference.odt
108109 , optEPUBStylesheet :: Maybe String -- ^ EPUB stylesheet
@@ -144,6 +145,7 @@ defaultOpts = Opt
144145 , optXeTeX = False
145146 , optSmart = False
146147 , optHtml5 = False
148+ , optChapters = False
147149 , optHTMLMathMethod = PlainMath
148150 , optReferenceODT = Nothing
149151 , optEPUBStylesheet = Nothing
@@ -233,6 +235,11 @@ options =
233235 (\opt -> return opt { optHtml5 = True }))
234236 "" -- "Produce HTML5 in HTML output"
235237
238+ , Option "" ["chapters"]
239+ (NoArg
240+ (\opt -> return opt { optChapters = True }))
241+ "" -- "Use chapter for top-level sections in LaTeX, DocBook"
242+
236243 , Option "m" ["latexmathml", "asciimathml"]
237244 (OptArg
238245 (\arg opt ->
@@ -637,6 +644,7 @@ main = do
637644 , optXeTeX = xetex
638645 , optSmart = smart
639646 , optHtml5 = html5
647+ , optChapters = chapters
640648 , optHTMLMathMethod = mathMethod
641649 , optReferenceODT = referenceODT
642650 , optEPUBStylesheet = epubStylesheet
@@ -781,7 +789,8 @@ main = do
781789 writerSourceDirectory = sourceDir,
782790 writerUserDataDir = datadir,
783791 writerHtml5 = html5 &&
784− "html" `isPrefixOf` writerName' }
792+ "html" `isPrefixOf` writerName',
793+ writerChapters = chapters }
785794
786795 when (isNonTextOutput writerName' && outputFile == "-") $
787796 do UTF8.hPutStrLn stderr ("Error: Cannot write " ++ writerName ++ " output to stdout.\n" ++