From 1a22e75352c05f345bb8a6ed02f14b9749355143 Mon Sep 17 00:00:00 2001
From: John MacFarlane <fiddlosopher@gmail.com>
Date: Sun, 18 Dec 2011 12:33:11 -0800
Subject: [PATCH] HTML writer: Retain ID attribute in highlighted code blocks.

---
 src/Text/Pandoc/Highlighting.hs | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/Text/Pandoc/Highlighting.hs b/src/Text/Pandoc/Highlighting.hs
index efa4fa20e..547ebc223 100644
--- a/src/Text/Pandoc/Highlighting.hs
+++ b/src/Text/Pandoc/Highlighting.hs
@@ -36,6 +36,7 @@ import Text.Highlighting.Kate ( languages, highlightAs, formatAsHtml, FormatOpti
 import Data.List (find)
 import Data.Maybe (fromMaybe)
 import Data.Char (toLower)
+import qualified Text.Blaze.Html5.Attributes as A
 
 highlightHtml :: Bool   -- ^ True if inline HTML
               -> Attr   -- ^ Attributes of the Code or CodeBlock
@@ -52,12 +53,14 @@ highlightHtml inline (id', classes, keyvals) rawCode =
                   Just _    -> [OptNumberLines]
       addBirdTracks = "literate" `elem` classes
       lcLanguages = map (map toLower) languages
+      addId = if null id' then id else (! A.id (toValue id'))
   in  case find (\c -> (map toLower c) `elem` lcLanguages) classes of
             Nothing        -> Left "Unknown or unsupported language"
             Just language  -> case highlightAs language rawCode of
                                    Left err -> Left err
-                                   Right hl -> Right $ formatAsHtml fmtOpts language $
-                                                       if addBirdTracks
+                                   Right hl -> Right $ addId
+                                                     $ formatAsHtml fmtOpts language
+                                                     $ if addBirdTracks
                                                           then map (("ot","> "):) hl
                                                           else hl