--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.
This commit is contained in:
John MacFarlane 2013-02-23 18:11:05 -08:00
parent a7245b453c
commit 756c8d492a
5 changed files with 20 additions and 20 deletions

8
README
View file

@ -397,9 +397,11 @@ Options affecting specific writers
: Number section headings in LaTeX, ConTeXt, HTML, or EPUB output. : Number section headings in LaTeX, ConTeXt, HTML, or EPUB output.
By default, sections are not numbered. By default, sections are not numbered.
`--number-from`=*NUMBER* `--number-offset`=*NUMBER[,NUMBER,...]*,
: Starting number for top-level section headings in HTML output. : Offset for section headings in HTML output (ignored in other
Ignored in other output formats. Implies `--number-sections`. 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` `--no-tex-ligatures`
: Do not convert quotation marks, apostrophes, and dashes to : Do not convert quotation marks, apostrophes, and dashes to

View file

@ -100,7 +100,7 @@ data Opt = Opt
, optVariables :: [(String,String)] -- ^ Template variables to set , optVariables :: [(String,String)] -- ^ Template variables to set
, optOutputFile :: String -- ^ Name of output file , optOutputFile :: String -- ^ Name of output file
, optNumberSections :: Bool -- ^ Number sections in LaTeX , 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 , optSectionDivs :: Bool -- ^ Put sections in div tags in HTML
, optIncremental :: Bool -- ^ Use incremental lists in Slidy/Slideous/S5 , optIncremental :: Bool -- ^ Use incremental lists in Slidy/Slideous/S5
, optSelfContained :: Bool -- ^ Make HTML accessible offline , optSelfContained :: Bool -- ^ Make HTML accessible offline
@ -157,7 +157,7 @@ defaultOpts = Opt
, optVariables = [] , optVariables = []
, optOutputFile = "-" -- "-" means stdout , optOutputFile = "-" -- "-" means stdout
, optNumberSections = False , optNumberSections = False
, optNumberFrom = 1 , optNumberOffset = [1,1,1,1,1,1]
, optSectionDivs = False , optSectionDivs = False
, optIncremental = False , optIncremental = False
, optSelfContained = False , optSelfContained = False
@ -469,15 +469,15 @@ options =
(\opt -> return opt { optNumberSections = True })) (\opt -> return opt { optNumberSections = True }))
"" -- "Number sections in LaTeX" "" -- "Number sections in LaTeX"
, Option "" ["number-from"] , Option "" ["number-offset"]
(ReqArg (ReqArg
(\arg opt -> (\arg opt ->
case safeRead arg of case safeRead ('[':arg ++ "]") of
Just n -> return opt { optNumberFrom = n, Just ns -> return opt { optNumberOffset = ns,
optNumberSections = True } optNumberSections = True }
_ -> err 57 "could not parse number-from") _ -> err 57 "could not parse number-offset")
"NUMBER") "NUMBERS")
"" -- "Starting number for sections" "" -- "Starting number for sections, subsections, etc."
, Option "" ["no-tex-ligatures"] , Option "" ["no-tex-ligatures"]
(NoArg (NoArg
@ -841,7 +841,7 @@ main = do
, optTemplate = templatePath , optTemplate = templatePath
, optOutputFile = outputFile , optOutputFile = outputFile
, optNumberSections = numberSections , optNumberSections = numberSections
, optNumberFrom = numberFrom , optNumberOffset = numberFrom
, optSectionDivs = sectionDivs , optSectionDivs = sectionDivs
, optIncremental = incremental , optIncremental = incremental
, optSelfContained = selfContained , optSelfContained = selfContained
@ -1035,7 +1035,7 @@ main = do
writerBiblioFiles = reffiles, writerBiblioFiles = reffiles,
writerIgnoreNotes = False, writerIgnoreNotes = False,
writerNumberSections = numberSections, writerNumberSections = numberSections,
writerNumberFrom = numberFrom, writerNumberOffset = numberFrom,
writerSectionDivs = sectionDivs, writerSectionDivs = sectionDivs,
writerReferenceLinks = referenceLinks, writerReferenceLinks = referenceLinks,
writerWrapText = wrap, writerWrapText = wrap,

View file

@ -270,7 +270,7 @@ data WriterOptions = WriterOptions
, writerHTMLMathMethod :: HTMLMathMethod -- ^ How to print math in HTML , writerHTMLMathMethod :: HTMLMathMethod -- ^ How to print math in HTML
, writerIgnoreNotes :: Bool -- ^ Ignore footnotes (used in making toc) , writerIgnoreNotes :: Bool -- ^ Ignore footnotes (used in making toc)
, writerNumberSections :: Bool -- ^ Number sections in LaTeX , 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 , writerSectionDivs :: Bool -- ^ Put sections in div tags in HTML
, writerExtensions :: Set Extension -- ^ Markdown extensions that can be used , writerExtensions :: Set Extension -- ^ Markdown extensions that can be used
, writerReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst , writerReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst
@ -314,7 +314,7 @@ instance Default WriterOptions where
, writerHTMLMathMethod = PlainMath , writerHTMLMathMethod = PlainMath
, writerIgnoreNotes = False , writerIgnoreNotes = False
, writerNumberSections = False , writerNumberSections = False
, writerNumberFrom = 1 , writerNumberOffset = [0,0,0,0,0,0]
, writerSectionDivs = False , writerSectionDivs = False
, writerExtensions = pandocExtensions , writerExtensions = pandocExtensions
, writerReferenceLinks = False , writerReferenceLinks = False

View file

@ -149,7 +149,7 @@ writeEPUB opts doc@(Pandoc meta _) = do
let chapToEntry :: Int -> [Block] -> Entry let chapToEntry :: Int -> [Block] -> Entry
chapToEntry num bs = mkEntry (showChapter num) chapToEntry num bs = mkEntry (showChapter num)
$ renderHtml $ renderHtml
$ writeHtml opts'{ writerNumberFrom = num } $ writeHtml opts'{ writerNumberOffset = [num - 1] }
$ case bs of $ case bs of
(Header _ _ xs : _) -> Pandoc (Meta xs [] []) bs (Header _ _ xs : _) -> Pandoc (Meta xs [] []) bs
_ -> Pandoc (Meta [] [] []) bs _ -> Pandoc (Meta [] [] []) bs

View file

@ -274,9 +274,7 @@ elementToHtml :: Int -> WriterOptions -> Element -> State WriterState Html
elementToHtml _slideLevel opts (Blk block) = blockToHtml opts block elementToHtml _slideLevel opts (Blk block) = blockToHtml opts block
elementToHtml slideLevel opts (Sec level num (id',classes,keyvals) title' elements) = do elementToHtml slideLevel opts (Sec level num (id',classes,keyvals) title' elements) = do
let slide = writerSlideVariant opts /= NoSlides && level <= slideLevel let slide = writerSlideVariant opts /= NoSlides && level <= slideLevel
let num' = case num of let num' = zipWith (+) num (writerNumberOffset opts)
(n:ns) -> n + writerNumberFrom opts - 1 : ns
[] -> []
modify $ \st -> st{stSecNum = num'} -- update section number modify $ \st -> st{stSecNum = num'} -- update section number
-- always use level 1 for slide titles -- always use level 1 for slide titles
let level' = if slide then 1 else level let level' = if slide then 1 else level