Skip to content

Commit

Permalink
Fixed numbering mismatch between TOC and sections in HTML.
Browse files Browse the repository at this point in the history
Also made `--number-offset` affect TOC numbering as well
as section numbering, as it should have all along.

Closes jgm#789.
  • Loading branch information
John MacFarlane authored and jamiefolson committed Mar 21, 2013
1 parent d53e89b commit b207528
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions pandoc.hs
Expand Up @@ -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
, optNumberOffset :: [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
Expand Down Expand Up @@ -158,7 +158,7 @@ defaultOpts = Opt
, optVariables = []
, optOutputFile = "-" -- "-" means stdout
, optNumberSections = False
, optNumberOffset = [1,1,1,1,1,1]
, optNumberOffset = [0,0,0,0,0,0]
, optSectionDivs = False
, optIncremental = False
, optSelfContained = False
Expand Down Expand Up @@ -1046,7 +1046,7 @@ main = do
writerBiblioFiles = reffiles,
writerIgnoreNotes = False,
writerNumberSections = numberSections,
writerNumberOffset = numberFrom,
writerNumberOffset = numberFrom,
writerSectionDivs = sectionDivs,
writerReferenceLinks = referenceLinks,
writerWrapText = wrap,
Expand Down
3 changes: 2 additions & 1 deletion src/Text/Pandoc/Writers/HTML.hs
Expand Up @@ -266,10 +266,11 @@ showSecNum = concat . intersperse "." . map show
elementToListItem :: WriterOptions -> Element -> State WriterState (Maybe Html)
elementToListItem opts (Sec lev num (id',classes,_) headerText subsecs)
| lev <= writerTOCDepth opts = do
let num' = zipWith (+) num (writerNumberOffset opts ++ repeat 0)
let sectnum = if writerNumberSections opts && not (null num) &&
"unnumbered" `notElem` classes
then (H.span ! A.class_ "toc-section-number"
$ toHtml $ showSecNum num) >> preEscapedString " "
$ toHtml $ showSecNum num') >> preEscapedString " "
else mempty
txt <- liftM (sectnum >>) $ inlineListToHtml opts headerText
subHeads <- mapM (elementToListItem opts) subsecs >>= return . catMaybes
Expand Down

0 comments on commit b207528

Please sign in to comment.