From 756c8d492a3793a8a0c2b750dac6005885b9a2d0 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 23 Feb 2013 18:11:05 -0800 Subject: [PATCH] `--number-from` -> `--number-offset` Also `writerNumberFrom` -> `writeNumberOffset`. The offset is a list of numbers (0 by default). These are added to the section, subsection, etc. numbers that would have been generated automatically. --- README | 8 +++++--- pandoc.hs | 22 +++++++++++----------- src/Text/Pandoc/Options.hs | 4 ++-- src/Text/Pandoc/Writers/EPUB.hs | 2 +- src/Text/Pandoc/Writers/HTML.hs | 4 +--- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/README b/README index 853ea282f..3afaabab0 100644 --- a/README +++ b/README @@ -397,9 +397,11 @@ Options affecting specific writers : Number section headings in LaTeX, ConTeXt, HTML, or EPUB output. By default, sections are not numbered. -`--number-from`=*NUMBER* -: Starting number for top-level section headings in HTML output. - Ignored in other output formats. Implies `--number-sections`. +`--number-offset`=*NUMBER[,NUMBER,...]*, +: Offset for section headings in HTML output (ignored in other + output formats). The first number is added to the section number for + top-level headers, the second for second-level headers, and so on. + Offsets are 0 by default. Implies `--number-sections`. `--no-tex-ligatures` : Do not convert quotation marks, apostrophes, and dashes to diff --git a/pandoc.hs b/pandoc.hs index 2c904984d..c777a3065 100644 --- a/pandoc.hs +++ b/pandoc.hs @@ -100,7 +100,7 @@ data Opt = Opt , optVariables :: [(String,String)] -- ^ Template variables to set , optOutputFile :: String -- ^ Name of output file , optNumberSections :: Bool -- ^ Number sections in LaTeX - , optNumberFrom :: Int -- ^ Starting number for sections + , optNumberOffset :: [Int] -- ^ Starting number for sections , optSectionDivs :: Bool -- ^ Put sections in div tags in HTML , optIncremental :: Bool -- ^ Use incremental lists in Slidy/Slideous/S5 , optSelfContained :: Bool -- ^ Make HTML accessible offline @@ -157,7 +157,7 @@ defaultOpts = Opt , optVariables = [] , optOutputFile = "-" -- "-" means stdout , optNumberSections = False - , optNumberFrom = 1 + , optNumberOffset = [1,1,1,1,1,1] , optSectionDivs = False , optIncremental = False , optSelfContained = False @@ -469,15 +469,15 @@ options = (\opt -> return opt { optNumberSections = True })) "" -- "Number sections in LaTeX" - , Option "" ["number-from"] + , Option "" ["number-offset"] (ReqArg (\arg opt -> - case safeRead arg of - Just n -> return opt { optNumberFrom = n, - optNumberSections = True } - _ -> err 57 "could not parse number-from") - "NUMBER") - "" -- "Starting number for sections" + case safeRead ('[':arg ++ "]") of + Just ns -> return opt { optNumberOffset = ns, + optNumberSections = True } + _ -> err 57 "could not parse number-offset") + "NUMBERS") + "" -- "Starting number for sections, subsections, etc." , Option "" ["no-tex-ligatures"] (NoArg @@ -841,7 +841,7 @@ main = do , optTemplate = templatePath , optOutputFile = outputFile , optNumberSections = numberSections - , optNumberFrom = numberFrom + , optNumberOffset = numberFrom , optSectionDivs = sectionDivs , optIncremental = incremental , optSelfContained = selfContained @@ -1035,7 +1035,7 @@ main = do writerBiblioFiles = reffiles, writerIgnoreNotes = False, writerNumberSections = numberSections, - writerNumberFrom = numberFrom, + writerNumberOffset = numberFrom, writerSectionDivs = sectionDivs, writerReferenceLinks = referenceLinks, writerWrapText = wrap, diff --git a/src/Text/Pandoc/Options.hs b/src/Text/Pandoc/Options.hs index ab5cf4c43..39fa2a1b2 100644 --- a/src/Text/Pandoc/Options.hs +++ b/src/Text/Pandoc/Options.hs @@ -270,7 +270,7 @@ data WriterOptions = WriterOptions , writerHTMLMathMethod :: HTMLMathMethod -- ^ How to print math in HTML , writerIgnoreNotes :: Bool -- ^ Ignore footnotes (used in making toc) , writerNumberSections :: Bool -- ^ Number sections in LaTeX - , writerNumberFrom :: Int -- ^ Starting section number + , writerNumberOffset :: [Int] -- ^ Starting number for section, subsection, ... , writerSectionDivs :: Bool -- ^ Put sections in div tags in HTML , writerExtensions :: Set Extension -- ^ Markdown extensions that can be used , writerReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst @@ -314,7 +314,7 @@ instance Default WriterOptions where , writerHTMLMathMethod = PlainMath , writerIgnoreNotes = False , writerNumberSections = False - , writerNumberFrom = 1 + , writerNumberOffset = [0,0,0,0,0,0] , writerSectionDivs = False , writerExtensions = pandocExtensions , writerReferenceLinks = False diff --git a/src/Text/Pandoc/Writers/EPUB.hs b/src/Text/Pandoc/Writers/EPUB.hs index d25efa672..048f90da1 100644 --- a/src/Text/Pandoc/Writers/EPUB.hs +++ b/src/Text/Pandoc/Writers/EPUB.hs @@ -149,7 +149,7 @@ writeEPUB opts doc@(Pandoc meta _) = do let chapToEntry :: Int -> [Block] -> Entry chapToEntry num bs = mkEntry (showChapter num) $ renderHtml - $ writeHtml opts'{ writerNumberFrom = num } + $ writeHtml opts'{ writerNumberOffset = [num - 1] } $ case bs of (Header _ _ xs : _) -> Pandoc (Meta xs [] []) bs _ -> Pandoc (Meta [] [] []) bs diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs index d8da74d3a..477087166 100644 --- a/src/Text/Pandoc/Writers/HTML.hs +++ b/src/Text/Pandoc/Writers/HTML.hs @@ -274,9 +274,7 @@ elementToHtml :: Int -> WriterOptions -> Element -> State WriterState Html elementToHtml _slideLevel opts (Blk block) = blockToHtml opts block elementToHtml slideLevel opts (Sec level num (id',classes,keyvals) title' elements) = do let slide = writerSlideVariant opts /= NoSlides && level <= slideLevel - let num' = case num of - (n:ns) -> n + writerNumberFrom opts - 1 : ns - [] -> [] + let num' = zipWith (+) num (writerNumberOffset opts) modify $ \st -> st{stSecNum = num'} -- update section number -- always use level 1 for slide titles let level' = if slide then 1 else level