git.iko.soy/typeable/pandoc
on master help sign in
HTML writer: hlint improvements.
982d2f6John MacFarlane
src/Text/Pandoc/Writers/HTML.hs+22−25
@@ -41,9 +41,8 @@ import Numeric (showHex)
41import Text.DocLayout (render, literal)
41import Text.DocLayout (render, literal)
42import Prelude
42import Prelude
43import Text.Blaze.Internal (MarkupM (Empty), customLeaf, customParent)
43import Text.Blaze.Internal (MarkupM (Empty), customLeaf, customParent)
44−import Text.DocTemplates (FromContext (lookupContext))
44+import Text.DocTemplates (FromContext (lookupContext), Context (..))
45import Text.Blaze.Html hiding (contents)
45import Text.Blaze.Html hiding (contents)
46−import Text.DocTemplates (Context (..))
47import Text.Pandoc.Definition
46import Text.Pandoc.Definition
48import Text.Pandoc.Highlighting (formatHtmlBlock, formatHtmlInline, highlight,
47import Text.Pandoc.Highlighting (formatHtmlBlock, formatHtmlInline, highlight,
49 styleToCss)
48 styleToCss)
@@ -941,15 +940,14 @@ toListItem opts item = nl opts >> H.li item
941blockListToHtml :: PandocMonad m
940blockListToHtml :: PandocMonad m
942 => WriterOptions -> [Block] -> StateT WriterState m Html
941 => WriterOptions -> [Block] -> StateT WriterState m Html
943blockListToHtml opts lst =
942blockListToHtml opts lst =
944− (mconcat . intersperse (nl opts) . filter nonempty)
943+ mconcat . intersperse (nl opts) . filter nonempty
945 <$> mapM (blockToHtml opts) lst
944 <$> mapM (blockToHtml opts) lst
946 where nonempty (Empty _) = False
945 where nonempty (Empty _) = False
947 nonempty _ = True
946 nonempty _ = True
948
947
949-- | Convert list of Pandoc inline elements to HTML.
948-- | Convert list of Pandoc inline elements to HTML.
950inlineListToHtml :: PandocMonad m => WriterOptions -> [Inline] -> StateT WriterState m Html
949inlineListToHtml :: PandocMonad m => WriterOptions -> [Inline] -> StateT WriterState m Html
951−inlineListToHtml opts lst =
950+inlineListToHtml opts lst = mconcat <$> mapM (inlineToHtml opts) lst
952− mapM (inlineToHtml opts) lst >>= return . mconcat
953
951
954-- | Annotates a MathML expression with the tex source
952-- | Annotates a MathML expression with the tex source
955annotateMML :: XML.Element -> Text -> XML.Element
953annotateMML :: XML.Element -> Text -> XML.Element
@@ -1011,37 +1009,36 @@ inlineToHtml opts inline = do
1011 ]
1009 ]
1012 ]
1010 ]
1013
1011
1014− (Emph lst) -> inlineListToHtml opts lst >>= return . H.em
1012+ (Emph lst) -> H.em <$> inlineListToHtml opts lst
1015− (Strong lst) -> inlineListToHtml opts lst >>= return . H.strong
1013+ (Strong lst) -> H.strong <$> inlineListToHtml opts lst
1016− (Code attr@(ids,cs,kvs) str)
1014+ (Code attr@(ids,cs,kvs) str)
1017 -> case hlCode of
1015 -> case hlCode of
1018 Left msg -> do
1016 Left msg -> do
1019 unless (T.null msg) $
1017 unless (T.null msg) $
1020 report $ CouldNotHighlight msg
1018 report $ CouldNotHighlight msg
1021− addAttrs opts (ids,cs',kvs) $
1019+ addAttrs opts (ids,cs',kvs) $
1022− maybe H.code id sampOrVar $
1020+ fromMaybe H.code sampOrVar $
1023 strToHtml str
1021 strToHtml str
1024 Right h -> do
1022 Right h -> do
1025 modify $ \st -> st{ stHighlighting = True }
1023 modify $ \st -> st{ stHighlighting = True }
1026− addAttrs opts (ids,[],kvs) $
1024+ addAttrs opts (ids,[],kvs) $
1027− maybe id id sampOrVar $ h
1025+ fromMaybe id sampOrVar h
1028 where hlCode = if isJust (writerHighlightStyle opts)
1026 where hlCode = if isJust (writerHighlightStyle opts)
1029 then highlight
1027 then highlight
1030 (writerSyntaxMap opts)
1028 (writerSyntaxMap opts)
1031 formatHtmlInline attr str
1029 formatHtmlInline attr str
1032 else Left ""
1030 else Left ""
1033− (sampOrVar,cs') =
1031+ (sampOrVar,cs')
1034− if "sample" `elem` cs
1032+ | "sample" `elem` cs =
1035− then (Just H.samp,"sample" `delete` cs)
1033+ (Just H.samp,"sample" `delete` cs)
1036− else if "variable" `elem` cs
1034+ | "variable" `elem` cs =
1037− then (Just H.var,"variable" `delete` cs)
1035+ (Just H.var,"variable" `delete` cs)
1038− else (Nothing,cs)
1036+ | otherwise = (Nothing,cs)
1039− (Strikeout lst) -> inlineListToHtml opts lst >>=
1037+ (Strikeout lst) -> H.del <$> inlineListToHtml opts lst
1040− return . H.del
1041− (SmallCaps lst) -> inlineListToHtml opts lst >>=
1042− return . (H.span ! A.class_ "smallcaps")
1038+ (SmallCaps lst) -> (H.span ! A.class_ "smallcaps") <$>
1039+ inlineListToHtml opts lst
1043− (Superscript lst) -> inlineListToHtml opts lst >>= return . H.sup
1040+ (Superscript lst) -> H.sup <$> inlineListToHtml opts lst
1044− (Subscript lst) -> inlineListToHtml opts lst >>= return . H.sub
1041+ (Subscript lst) -> H.sub <$> inlineListToHtml opts lst
1045 (Quoted quoteType lst) ->
1042 (Quoted quoteType lst) ->
1046 let (leftQuote, rightQuote) = case quoteType of
1043 let (leftQuote, rightQuote) = case quoteType of
1047 SingleQuote -> (strToHtml "‘",
1044 SingleQuote -> (strToHtml "‘",
@@ -1210,7 +1207,7 @@ blockListToNote opts ref blocks = do
1210 html5 <- gets stHtml5
1207 html5 <- gets stHtml5
1211 -- If last block is Para or Plain, include the backlink at the end of
1208 -- If last block is Para or Plain, include the backlink at the end of
1212 -- that block. Otherwise, insert a new Plain block with the backlink.
1209 -- that block. Otherwise, insert a new Plain block with the backlink.
1213− let kvs = if html5 then [("role","doc-backlink")] else []
1210+ let kvs = [("role","doc-backlink") | html5]
1214 let backlink = [Link ("",["footnote-back"],kvs)
1211 let backlink = [Link ("",["footnote-back"],kvs)
1215 [Str "↩"] ("#" <> "fnref" <> ref,"")]
1212 [Str "↩"] ("#" <> "fnref" <> ref,"")]
1216 let blocks' = if null blocks
1213 let blocks' = if null blocks