Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions pandoc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ data Opt = Opt
, optVariables :: [(String,String)] -- ^ Template variables to set
, optMetadata :: M.Map String MetaValue -- ^ Metadata fields to set
, optOutputFile :: String -- ^ Name of output file
, optNumberSections :: Bool -- ^ Number sections in LaTeX
, optNumberFigures :: Bool -- ^ Number figures in LaTeX and HTML output
, optNumberSections :: Bool -- ^ Number sections in LaTeX and HTML output
, optNumberOffset :: [Int] -- ^ Starting number for sections
, optSectionDivs :: Bool -- ^ Put sections in div tags in HTML
, optIncremental :: Bool -- ^ Use incremental lists in Slidy/Slideous/S5
Expand Down Expand Up @@ -196,6 +197,7 @@ defaultOpts = Opt
, optVariables = []
, optMetadata = M.empty
, optOutputFile = "-" -- "-" means stdout
, optNumberFigures = False
, optNumberSections = False
, optNumberOffset = [0,0,0,0,0,0]
, optSectionDivs = False
Expand Down Expand Up @@ -524,10 +526,15 @@ options =
(\opt -> return opt { optChapters = True }))
"" -- "Use chapter for top-level sections in LaTeX, DocBook"

, Option "" ["number-figures"]
(NoArg
(\opt -> return opt { optNumberFigures = True }))
"" -- "Number figures in LaTeX and HTML"

, Option "N" ["number-sections"]
(NoArg
(\opt -> return opt { optNumberSections = True }))
"" -- "Number sections in LaTeX"
"" -- "Number sections in LaTeX and HTML"

, Option "" ["number-offset"]
(ReqArg
Expand Down Expand Up @@ -938,8 +945,9 @@ main = do
, optTransforms = transforms
, optTemplate = templatePath
, optOutputFile = outputFile
, optNumberFigures = numberFigures
, optNumberSections = numberSections
, optNumberOffset = numberFrom
, optNumberOffset = numberFrom
, optSectionDivs = sectionDivs
, optIncremental = incremental
, optSelfContained = selfContained
Expand Down Expand Up @@ -1112,6 +1120,7 @@ main = do
writerIncremental = incremental,
writerCiteMethod = citeMethod,
writerIgnoreNotes = False,
writerNumberFigures = numberFigures,
writerNumberSections = numberSections,
writerNumberOffset = numberFrom,
writerSectionDivs = sectionDivs,
Expand Down
4 changes: 3 additions & 1 deletion src/Text/Pandoc/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ data WriterOptions = WriterOptions
, writerIncremental :: Bool -- ^ True if lists should be incremental
, writerHTMLMathMethod :: HTMLMathMethod -- ^ How to print math in HTML
, writerIgnoreNotes :: Bool -- ^ Ignore footnotes (used in making toc)
, writerNumberSections :: Bool -- ^ Number sections in LaTeX
, writerNumberFigures :: Bool -- ^ Number figures in LaTeX and HTML
, writerNumberSections :: Bool -- ^ Number sections in LaTeX and HTML
, 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
Expand Down Expand Up @@ -318,6 +319,7 @@ instance Default WriterOptions where
, writerIncremental = False
, writerHTMLMathMethod = PlainMath
, writerIgnoreNotes = False
, writerNumberFigures = False
, writerNumberSections = False
, writerNumberOffset = [0,0,0,0,0,0]
, writerSectionDivs = False
Expand Down
15 changes: 11 additions & 4 deletions src/Text/Pandoc/Writers/HTML.hs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@ data WriterState = WriterState
, stQuotes :: Bool -- ^ <q> tag is used
, stHighlighting :: Bool -- ^ Syntax highlighting is used
, stSecNum :: [Int] -- ^ Number of current section
, stFigNum :: Int -- ^ Number of current figure
}

defaultWriterState :: WriterState
defaultWriterState = WriterState {stNotes= [], stMath = False, stQuotes = False,
stHighlighting = False, stSecNum = []}
stHighlighting = False, stSecNum = [], stFigNum = 1}

-- Helpers to render HTML with the appropriate function.

Expand Down Expand Up @@ -410,12 +411,18 @@ blockToHtml opts (Plain lst) = inlineListToHtml opts lst
-- title beginning with fig: indicates that the image is a figure
blockToHtml opts (Para [Image txt (s,'f':'i':'g':':':tit)]) = do
img <- inlineToHtml opts (Image txt (s,tit))
num <- stFigNum `liftM` get
modify $ \st -> st{stFigNum = num+1} -- update figure number
let label = if writerNumberFigures opts
then H.span ! A.class_ "figure-number" $ (toHtml $ "Figure "++show num)
else mempty
let tocapt = if writerHtml5 opts
then H5.figcaption
else H.p ! A.class_ "caption"
capt <- if null txt
then return mempty
else tocapt `fmap` inlineListToHtml opts txt
capt <- case () of
_ | writerNumberFigures opts -> (tocapt . (label >>)) `fmap` (inlineListToHtml opts txt)
_ | null txt -> return mempty
_ | otherwise -> tocapt `fmap` (inlineListToHtml opts txt)
return $ if writerHtml5 opts
then H5.figure $ mconcat
[nl opts, img, capt, nl opts]
Expand Down