@@ -101,6 +101,7 @@ data WriterState = WriterState
101101 , stHtml5 :: Bool -- ^ Use HTML5
102102 , stEPUBVersion :: Maybe EPUBVersion -- ^ EPUB version if for epub
103103 , stSlideVariant :: HTMLSlideVariant
104+ , stCodeBlockNum :: Int -- ^ Number of code block
104105 }
105106
106107defaultWriterState :: WriterState
@@ -108,7 +109,8 @@ defaultWriterState = WriterState {stNotes= [], stMath = False, stQuotes = False,
108109 stHighlighting = False, stSecNum = [],
109110 stElement = False, stHtml5 = False,
110111 stEPUBVersion = Nothing,
111− stSlideVariant = NoSlides}
112+ stSlideVariant = NoSlides,
113+ stCodeBlockNum = 0}
112114
113115-- Helpers to render HTML with the appropriate function.
114116
@@ -703,6 +705,12 @@ blockToHtml _ HorizontalRule = do
703705 html5 <- gets stHtml5
704706 return $ if html5 then H5.hr else H.hr
705707blockToHtml opts (CodeBlock (id',classes,keyvals) rawCode) = do
708+ id'' <- if null id'
709+ then do
710+ modify $ \st -> st{ stCodeBlockNum = stCodeBlockNum st + 1 }
711+ codeblocknum <- gets stCodeBlockNum
712+ return ("cb" ++ show codeblocknum)
713+ else return id'
706714 let tolhs = isEnabled Ext_literate_haskell opts &&
707715 any (\c -> map toLower c == "haskell") classes &&
708716 any (\c -> map toLower c == "literate") classes
@@ -716,7 +724,7 @@ blockToHtml opts (CodeBlock (id',classes,keyvals) rawCode) = do
716724 else rawCode
717725 hlCode = if isJust (writerHighlightStyle opts)
718726 then highlight (writerSyntaxMap opts) formatHtmlBlock
719− (id',classes',keyvals) adjCode
727+ (id'',classes',keyvals) adjCode
720728 else Left ""
721729 case hlCode of
722730 Left msg -> do
@@ -725,7 +733,7 @@ blockToHtml opts (CodeBlock (id',classes,keyvals) rawCode) = do
725733 addAttrs opts (id',classes,keyvals)
726734 $ H.pre $ H.code $ toHtml adjCode
727735 Right h -> modify (\st -> st{ stHighlighting = True }) >>
728− addAttrs opts (id',[],keyvals) h
736+ addAttrs opts (id'',[],keyvals) h
729737blockToHtml opts (BlockQuote blocks) = do
730738 -- in S5, treat list in blockquote specially
731739 -- if default is incremental, make it nonincremental;