diff options
author | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2009-12-08 02:36:16 +0000 |
---|---|---|
committer | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2009-12-08 02:36:16 +0000 |
commit | 2ced785e95e0799f3c8a705e828e6522e11a8a98 (patch) | |
tree | 5023d6cf6debc6971549a389ef98a12fd8a3955a /src/Text/Pandoc/Writers/HTML.hs | |
parent | 05436988950d271f8a55ee48b4d7794da9b40172 (diff) | |
download | pandoc-2ced785e95e0799f3c8a705e828e6522e11a8a98.tar.gz |
Added optional section numbering in HTML output.
This involves a change to the Element data structure,
including a section number as well as an id and title
for each section. Section numbers are lists of integers;
this should allow different numbering schemes to be used
in the future. Currently [1,2,3] -> 1.2.3.
Resolves Issue #150.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@1658 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'src/Text/Pandoc/Writers/HTML.hs')
-rw-r--r-- | src/Text/Pandoc/Writers/HTML.hs | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs index 9e397477e..56398b263 100644 --- a/src/Text/Pandoc/Writers/HTML.hs +++ b/src/Text/Pandoc/Writers/HTML.hs @@ -38,7 +38,7 @@ import Text.Pandoc.Highlighting ( highlightHtml, defaultHighlightingCss ) import Text.Pandoc.XML (stripTags) import Numeric ( showHex ) import Data.Char ( ord, toLower ) -import Data.List ( isPrefixOf ) +import Data.List ( isPrefixOf, intersperse ) import Data.Maybe ( catMaybes ) import qualified Data.Set as S import Control.Monad.State @@ -156,12 +156,19 @@ tableOfContents opts sects = do contents <- mapM (elementToListItem opts') sects return $ thediv ! [prefixedId opts' "TOC"] $ unordList $ catMaybes contents +-- | Convert section number to inline +showSecNum :: [Int] -> Inline +showSecNum = Str . concat . intersperse "." . map show + -- | Converts an Element to a list item for a table of contents, -- retrieving the appropriate identifier from state. elementToListItem :: WriterOptions -> Element -> State WriterState (Maybe Html) elementToListItem _ (Blk _) = return Nothing -elementToListItem opts (Sec _ id' headerText subsecs) = do - txt <- inlineListToHtml opts headerText +elementToListItem opts (Sec _ num id' headerText subsecs) = do + let headerText' = if writerNumberSections opts + then showSecNum num : Space : headerText + else headerText + txt <- inlineListToHtml opts headerText' subHeads <- mapM (elementToListItem opts) subsecs >>= return . catMaybes let subList = if null subHeads then noHtml @@ -171,9 +178,12 @@ elementToListItem opts (Sec _ id' headerText subsecs) = do -- | Convert an Element to Html. elementToHtml :: WriterOptions -> Element -> State WriterState Html elementToHtml opts (Blk block) = blockToHtml opts block -elementToHtml opts (Sec level id' title' elements) = do +elementToHtml opts (Sec level num id' title' elements) = do innerContents <- mapM (elementToHtml opts) elements - header' <- blockToHtml opts (Header level title') + let title'' = if writerNumberSections opts + then showSecNum num : Space : title' + else title' + header' <- blockToHtml opts (Header level title'') return $ if writerS5 opts || (writerStrictMarkdown opts && not (writerTableOfContents opts)) -- S5 gets confused by the extra divs around sections then toHtmlFromList (header' : innerContents) |