git.iko.soy/typeable/pandoc
on master help sign in
HTML writer: Refactored adding attributes to html element.
a50b832John MacFarlane
src/Text/Pandoc/Writers/HTML.hs+10−9
@@ -279,7 +279,7 @@ elementToHtml slideLevel opts (Sec level num (id',classes,keyvals) title' elemen
279 let titleSlide = slide && level < slideLevel
279 let titleSlide = slide && level < slideLevel
280 header' <- if title' == [Str "\0"] -- marker for hrule
280 header' <- if title' == [Str "\0"] -- marker for hrule
281 then return mempty
281 then return mempty
282− else blockToHtml opts (Header level' (id',[],[]) title')
282+ else blockToHtml opts (Header level' (id',classes,keyvals) title')
283 let isSec (Sec _ _ _ _ _) = True
283 let isSec (Sec _ _ _ _ _) = True
284 isSec (Blk _) = False
284 isSec (Blk _) = False
285 innerContents <- mapM (elementToHtml slideLevel opts)
285 innerContents <- mapM (elementToHtml slideLevel opts)
@@ -371,6 +371,9 @@ obfuscateChar char =
371obfuscateString :: String -> String
371obfuscateString :: String -> String
372obfuscateString = concatMap obfuscateChar . fromEntities
372obfuscateString = concatMap obfuscateChar . fromEntities
373
373
374+addAttrs :: WriterOptions -> Attr -> Html -> Html
375+addAttrs opts attr h = foldl (!) h (attrsToHtml opts attr)
376+
374attrsToHtml :: WriterOptions -> Attr -> [Attribute]
377attrsToHtml :: WriterOptions -> Attr -> [Attribute]
375attrsToHtml opts (id',classes',keyvals) =
378attrsToHtml opts (id',classes',keyvals) =
376 [A.class_ (toValue $ unwords classes') | not (null classes')] ++
379 [A.class_ (toValue $ unwords classes') | not (null classes')] ++
@@ -425,11 +428,10 @@ blockToHtml opts (CodeBlock (id',classes,keyvals) rawCode) = do
425 then unlines . map ("> " ++) . lines $ rawCode
428 then unlines . map ("> " ++) . lines $ rawCode
426 else rawCode
429 else rawCode
427 case highlight formatHtmlBlock (id',classes,keyvals) adjCode of
430 case highlight formatHtmlBlock (id',classes,keyvals) adjCode of
428− Nothing -> let attrs = attrsToHtml opts (id', classes', keyvals)
431+ Nothing -> return $ addAttrs opts (id',classes,keyvals)
429− in return $ foldl (!) H.pre attrs $ H.code
430− $ toHtml adjCode
432+ $ H.pre $ H.code $ toHtml adjCode
431 Just h -> modify (\st -> st{ stHighlighting = True }) >>
433 Just h -> modify (\st -> st{ stHighlighting = True }) >>
432− return (foldl (!) h (attrsToHtml opts (id',[],keyvals)))
434+ return (addAttrs opts (id',[],keyvals) h)
433blockToHtml opts (BlockQuote blocks) =
435blockToHtml opts (BlockQuote blocks) =
434 -- in S5, treat list in blockquote specially
436 -- in S5, treat list in blockquote specially
435 -- if default is incremental, make it nonincremental;
437 -- if default is incremental, make it nonincremental;
@@ -599,12 +601,11 @@ inlineToHtml opts inline =
599 (Strong lst) -> inlineListToHtml opts lst >>= return . H.strong
601 (Strong lst) -> inlineListToHtml opts lst >>= return . H.strong
600 (Code attr str) -> case highlight formatHtmlInline attr str of
602 (Code attr str) -> case highlight formatHtmlInline attr str of
601 Nothing -> return
603 Nothing -> return
602− $ foldl (!) H.code (attrsToHtml opts attr)
604+ $ addAttrs opts attr
603− $ strToHtml str
605+ $ H.code $ strToHtml str
604 Just h -> do
606 Just h -> do
605 modify $ \st -> st{ stHighlighting = True }
607 modify $ \st -> st{ stHighlighting = True }
606− return $ foldl (!) h $
607− attrsToHtml opts (id',[],keyvals)
608+ return $ addAttrs opts (id',[],keyvals) h
608 where (id',_,keyvals) = attr
609 where (id',_,keyvals) = attr
609 (Strikeout lst) -> inlineListToHtml opts lst >>=
610 (Strikeout lst) -> inlineListToHtml opts lst >>=
610 return . H.del
611 return . H.del