git.iko.soy/typeable/pandoc
on master help sign in
HTML writer: Refactored adding attributes to html element.
commita50b83266c46fef960ec01f2c1f14c31b39033c3 authorJohn MacFarlane <fiddlosopher@gmail.com> dateTue 12 Feb 2013, 21:29 (14 years ago) parent6d95984
1 file changed+10−9
src/Text/Pandoc/Writers/HTML.hs+10−9
src/Text/Pandoc/Writers/HTML.hs+10−9
@@ -279,7 +279,7 @@ elementToHtml slideLevel opts (Sec level num (id',classes,keyvals) title' elemen
279279 let titleSlide = slide && level < slideLevel
280280 header' <- if title' == [Str "\0"] -- marker for hrule
281281 then return mempty
282− else blockToHtml opts (Header level' (id',[],[]) title')
282+ else blockToHtml opts (Header level' (id',classes,keyvals) title')
283283 let isSec (Sec _ _ _ _ _) = True
284284 isSec (Blk _) = False
285285 innerContents <- mapM (elementToHtml slideLevel opts)
@@ -371,6 +371,9 @@ obfuscateChar char =
371371obfuscateString :: String -> String
372372obfuscateString = concatMap obfuscateChar . fromEntities
373373
374+addAttrs :: WriterOptions -> Attr -> Html -> Html
375+addAttrs opts attr h = foldl (!) h (attrsToHtml opts attr)
376+
374377attrsToHtml :: WriterOptions -> Attr -> [Attribute]
375378attrsToHtml opts (id',classes',keyvals) =
376379 [A.class_ (toValue $ unwords classes') | not (null classes')] ++
@@ -425,11 +428,10 @@ blockToHtml opts (CodeBlock (id',classes,keyvals) rawCode) = do
425428 then unlines . map ("> " ++) . lines $ rawCode
426429 else rawCode
427430 case highlight formatHtmlBlock (id',classes,keyvals) adjCode of
428− Nothing -> let attrs = attrsToHtml opts (id', classes', keyvals)
429− in return $ foldl (!) H.pre attrs $ H.code
430− $ toHtml adjCode
431+ Nothing -> return $ addAttrs opts (id',classes,keyvals)
432+ $ H.pre $ H.code $ toHtml adjCode
431433 Just h -> modify (\st -> st{ stHighlighting = True }) >>
432− return (foldl (!) h (attrsToHtml opts (id',[],keyvals)))
434+ return (addAttrs opts (id',[],keyvals) h)
433435blockToHtml opts (BlockQuote blocks) =
434436 -- in S5, treat list in blockquote specially
435437 -- if default is incremental, make it nonincremental;
@@ -599,12 +601,11 @@ inlineToHtml opts inline =
599601 (Strong lst) -> inlineListToHtml opts lst >>= return . H.strong
600602 (Code attr str) -> case highlight formatHtmlInline attr str of
601603 Nothing -> return
602− $ foldl (!) H.code (attrsToHtml opts attr)
603− $ strToHtml str
604+ $ addAttrs opts attr
605+ $ H.code $ strToHtml str
604606 Just h -> do
605607 modify $ \st -> st{ stHighlighting = True }
606− return $ foldl (!) h $
607− attrsToHtml opts (id',[],keyvals)
608+ return $ addAttrs opts (id',[],keyvals) h
608609 where (id',_,keyvals) = attr
609610 (Strikeout lst) -> inlineListToHtml opts lst >>=
610611 return . H.del