--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.
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

View file

@ -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,

View file

@ -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

View file

@ -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

View file

@ -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