@@ -144,13 +144,17 @@ writeHtml opts (Pandoc (Meta tit authors date) blocks) =
144144 then head' +++ body thebody
145145 else thebody
146146
147+-- | Like Text.XHtml's identifier, but adds the writerIdentifierPrefix
148+prefixedId :: WriterOptions -> String -> HtmlAttr
149+prefixedId opts s = identifier $ writerIdentifierPrefix opts ++ s
150+
147151-- | Construct table of contents from list of elements.
148152tableOfContents :: WriterOptions -> [Element] -> State WriterState Html
149153tableOfContents _ [] = return noHtml
150154tableOfContents opts sects = do
151155 let opts' = opts { writerIgnoreNotes = True }
152156 contents <- mapM (elementToListItem opts') sects
153− return $ thediv ! [identifier "TOC"] $ unordList $ catMaybes contents
157+ return $ thediv ! [prefixedId opts' "TOC"] $ unordList $ catMaybes contents
154158
155159-- | Converts an Element to a list item for a table of contents,
156160-- retrieving the appropriate identifier from state.
@@ -162,7 +166,7 @@ elementToListItem opts (Sec _ id' headerText subsecs) = do
162166 let subList = if null subHeads
163167 then noHtml
164168 else unordList subHeads
165− return $ Just $ (anchor ! [href ("#" ++ id')] $ txt) +++ subList
169+ return $ Just $ (anchor ! [href ("#" ++ writerIdentifierPrefix opts ++ id')] $ txt) +++ subList
166170
167171-- | Convert an Element to Html.
168172elementToHtml :: WriterOptions -> Element -> State WriterState Html
@@ -173,7 +177,7 @@ elementToHtml opts (Sec level id' title' elements) = do
173177 return $ if writerS5 opts || (writerStrictMarkdown opts && not (writerTableOfContents opts))
174178 -- S5 gets confused by the extra divs around sections
175179 then toHtmlFromList (header' : innerContents)
176− else thediv ! [identifier id'] << (header' : innerContents)
180+ else thediv ! [prefixedId opts id'] << (header' : innerContents)
177181
178182-- | Convert list of Note blocks to a footnote <div>.
179183-- Assumes notes are sorted.
@@ -258,7 +262,7 @@ blockToHtml opts (CodeBlock (id',classes,keyvals) rawCode) = do
258262 -- browsers ignore leading newlines in pre blocks
259263 let (leadingBreaks, rawCode') = span (=='\n') rawCode
260264 attrs = [theclass (unwords classes') | not (null classes')] ++
261− [identifier id' | not (null id')] ++
265+ [prefixedId opts id' | not (null id')] ++
262266 map (\(x,y) -> strAttr x y) keyvals
263267 in return $ pre ! attrs $ thecode <<
264268 (replicate (length leadingBreaks) br +++
@@ -282,7 +286,7 @@ blockToHtml opts (BlockQuote blocks) =
282286blockToHtml opts (Header level lst) = do
283287 contents <- inlineListToHtml opts lst
284288 let contents' = if writerTableOfContents opts
285− then anchor ! [href "#TOC"] $ contents
289+ then anchor ! [href $ "#" ++ writerIdentifierPrefix opts ++ "TOC"] $ contents
286290 else contents
287291 return $ case level of
288292 1 -> h1 contents'
@@ -465,9 +469,9 @@ inlineToHtml opts inline =
465469 htmlContents <- blockListToNote opts ref contents
466470 -- push contents onto front of notes
467471 put $ st {stNotes = (htmlContents:notes)}
468− return $ anchor ! [href ("#fn" ++ ref),
472+ return $ anchor ! [href ("#" ++ writerIdentifierPrefix opts ++ "fn" ++ ref),
469473 theclass "footnoteRef",
470− identifier ("fnref" ++ ref)] <<
474+ prefixedId opts ("fnref" ++ ref)] <<
471475 sup << ref
472476 (Cite _ il) -> inlineListToHtml opts il
473477
@@ -475,7 +479,7 @@ blockListToNote :: WriterOptions -> String -> [Block] -> State WriterState Html
475479blockListToNote opts ref blocks =
476480 -- If last block is Para or Plain, include the backlink at the end of
477481 -- that block. Otherwise, insert a new Plain block with the backlink.
478− let backlink = [HtmlInline $ " <a href=\"#fnref" ++ ref ++
482+ let backlink = [HtmlInline $ " <a href=\"#" ++ writerIdentifierPrefix opts ++ "fnref" ++ ref ++
479483 "\" class=\"footnoteBackLink\"" ++
480484 " title=\"Jump back to footnote " ++ ref ++ "\">↩</a>"]
481485 blocks' = if null blocks
@@ -490,5 +494,5 @@ blockListToNote opts ref blocks =
490494 _ -> otherBlocks ++ [lastBlock,
491495 Plain backlink]
492496 in do contents <- blockListToHtml opts blocks'
493− return $ li ! [identifier ("fn" ++ ref)] $ contents
497+ return $ li ! [prefixedId opts ("fn" ++ ref)] $ contents
494498