diff options
author | John MacFarlane <jgm@berkeley.edu> | 2011-01-16 08:57:32 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2011-01-16 08:58:29 -0800 |
commit | 9721b87c26861fd9495cd0697fe79c6b1b5e6211 (patch) | |
tree | 62c885c0e9fe7d2c382f72a12c4851563d42bd97 | |
parent | 53eb2c4828d09fa00dce327f0b69e252287d82ca (diff) | |
download | pandoc-9721b87c26861fd9495cd0697fe79c6b1b5e6211.tar.gz |
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.
-rw-r--r-- | src/Text/Pandoc/Shared.hs | 2 | ||||
-rw-r--r-- | src/Text/Pandoc/Writers/Docbook.hs | 7 | ||||
-rw-r--r-- | src/Text/Pandoc/Writers/LaTeX.hs | 2 | ||||
-rw-r--r-- | src/pandoc.hs | 11 |
4 files changed, 18 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index f757f4479..81c552e41 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -482,6 +482,7 @@ data WriterOptions = WriterOptions , writerCiteMethod :: CiteMethod -- ^ How to print cites , writerBiblioFiles :: [FilePath] -- ^ Biblio files to use for citations , writerHtml5 :: Bool -- ^ Produce HTML5 + , writerChapters :: Bool -- ^ Use "chapter" for top-level sects } deriving Show -- | Default writer options. @@ -512,6 +513,7 @@ defaultWriterOptions = , writerCiteMethod = Citeproc , writerBiblioFiles = [] , writerHtml5 = False + , writerChapters = False } -- diff --git a/src/Text/Pandoc/Writers/Docbook.hs b/src/Text/Pandoc/Writers/Docbook.hs index a53c3fb86..2706f3334 100644 --- a/src/Text/Pandoc/Writers/Docbook.hs +++ b/src/Text/Pandoc/Writers/Docbook.hs @@ -87,9 +87,12 @@ elementToDocbook opts (Sec _ _num id' title elements) = let elements' = if null elements then [Blk (Para [])] else elements - in inTags True "section" [("id",id')] $ + tag = if writerChapters opts + then "chapter" + else "section" + in inTags True tag [("id",id')] $ inTagsSimple "title" (inlinesToDocbook opts title) $$ - vcat (map (elementToDocbook opts) elements') + vcat (map (elementToDocbook opts{ writerChapters = False }) elements') -- | Convert a list of Pandoc blocks to Docbook. blocksToDocbook :: WriterOptions -> [Block] -> Doc diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs index 836e0f974..64a1e03ac 100644 --- a/src/Text/Pandoc/Writers/LaTeX.hs +++ b/src/Text/Pandoc/Writers/LaTeX.hs @@ -63,7 +63,7 @@ writeLaTeX options document = stVerbInNote = False, stEnumerate = False, stTable = False, stStrikeout = False, stSubscript = False, stUrl = False, stGraphics = False, - stLHS = False, stBook = False } + stLHS = False, stBook = writerChapters options } pandocToLaTeX :: WriterOptions -> Pandoc -> State WriterState String pandocToLaTeX options (Pandoc (Meta title authors date) blocks) = do diff --git a/src/pandoc.hs b/src/pandoc.hs index 2068f5fc6..065a6850a 100644 --- a/src/pandoc.hs +++ b/src/pandoc.hs @@ -103,6 +103,7 @@ data Opt = Opt , optXeTeX :: Bool -- ^ Format latex for xetex , optSmart :: Bool -- ^ Use smart typography , optHtml5 :: Bool -- ^ Produce HTML5 in HTML + , optChapters :: Bool -- ^ Use chapter for top-level sects , optHTMLMathMethod :: HTMLMathMethod -- ^ Method to print HTML math , optReferenceODT :: Maybe FilePath -- ^ Path of reference.odt , optEPUBStylesheet :: Maybe String -- ^ EPUB stylesheet @@ -144,6 +145,7 @@ defaultOpts = Opt , optXeTeX = False , optSmart = False , optHtml5 = False + , optChapters = False , optHTMLMathMethod = PlainMath , optReferenceODT = Nothing , optEPUBStylesheet = Nothing @@ -233,6 +235,11 @@ options = (\opt -> return opt { optHtml5 = True })) "" -- "Produce HTML5 in HTML output" + , Option "" ["chapters"] + (NoArg + (\opt -> return opt { optChapters = True })) + "" -- "Use chapter for top-level sections in LaTeX, DocBook" + , Option "m" ["latexmathml", "asciimathml"] (OptArg (\arg opt -> @@ -637,6 +644,7 @@ main = do , optXeTeX = xetex , optSmart = smart , optHtml5 = html5 + , optChapters = chapters , optHTMLMathMethod = mathMethod , optReferenceODT = referenceODT , optEPUBStylesheet = epubStylesheet @@ -781,7 +789,8 @@ main = do writerSourceDirectory = sourceDir, writerUserDataDir = datadir, writerHtml5 = html5 && - "html" `isPrefixOf` writerName' } + "html" `isPrefixOf` writerName', + writerChapters = chapters } when (isNonTextOutput writerName' && outputFile == "-") $ do UTF8.hPutStrLn stderr ("Error: Cannot write " ++ writerName ++ " output to stdout.\n" ++ |