From 0c9bb4040363d990cb1f59bcc5b39ff78508cad9 Mon Sep 17 00:00:00 2001
From: John MacFarlane <fiddlosopher@gmail.com>
Date: Thu, 28 Feb 2013 18:47:49 -0800
Subject: [PATCH] Textile writer:  Support header attributes.

---
 src/Text/Pandoc/Writers/Textile.hs | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/Text/Pandoc/Writers/Textile.hs b/src/Text/Pandoc/Writers/Textile.hs
index 0a071c1f8..a3f899159 100644
--- a/src/Text/Pandoc/Writers/Textile.hs
+++ b/src/Text/Pandoc/Writers/Textile.hs
@@ -122,10 +122,16 @@ blockToTextile _ (RawBlock f str) =
 
 blockToTextile _ HorizontalRule = return "<hr />\n"
 
-blockToTextile opts (Header level (ident,_,_) inlines) = do
+blockToTextile opts (Header level (ident,classes,keyvals) inlines) = do
   contents <- inlineListToTextile opts inlines
-  let attribs = if null ident then "" else "(#" ++ ident ++ ")"
-  let prefix = 'h' : show level ++ attribs ++ ". "
+  let identAttr = if null ident then "" else ('#':ident)
+  let classAttr = unwords classes
+  let attribs = if null identAttr && null classes
+                   then ""
+                   else "(" ++ unwords classes ++ identAttr ++ ")"
+  let lang = maybe "" (\x -> "[" ++ x ++ "]") $ lookup "lang" keyvals
+  let styles = maybe "" (\x -> "{" ++ x ++ "}") $ lookup "style" keyvals
+  let prefix = 'h' : show level ++ attribs ++ styles ++ lang ++ ". "
   return $ prefix ++ contents ++ "\n"
 
 blockToTextile _ (CodeBlock (_,classes,_) str) | any (all isSpace) (lines str) =