git.iko.soy/typeable/pandoc
on master help sign in
HTML writer: hlint improvements.
commit982d2f6cd3596ea3ef13ab472e8d85ef55db6555 authorJohn MacFarlane <jgm@berkeley.edu> dateWed 27 Nov 2019, 09:52 (7 years ago) parent3accc2a
1 file changed+22−25
src/Text/Pandoc/Writers/HTML.hs+22−25
src/Text/Pandoc/Writers/HTML.hs+22−25
@@ -41,9 +41,8 @@ import Numeric (showHex)
4141import Text.DocLayout (render, literal)
4242import Prelude
4343import Text.Blaze.Internal (MarkupM (Empty), customLeaf, customParent)
44−import Text.DocTemplates (FromContext (lookupContext))
44+import Text.DocTemplates (FromContext (lookupContext), Context (..))
4545import Text.Blaze.Html hiding (contents)
46−import Text.DocTemplates (Context (..))
4746import Text.Pandoc.Definition
4847import Text.Pandoc.Highlighting (formatHtmlBlock, formatHtmlInline, highlight,
4948 styleToCss)
@@ -941,15 +940,14 @@ toListItem opts item = nl opts >> H.li item
941940blockListToHtml :: PandocMonad m
942941 => WriterOptions -> [Block] -> StateT WriterState m Html
943942blockListToHtml opts lst =
944− (mconcat . intersperse (nl opts) . filter nonempty)
943+ mconcat . intersperse (nl opts) . filter nonempty
945944 <$> mapM (blockToHtml opts) lst
946945 where nonempty (Empty _) = False
947946 nonempty _ = True
948947
949948-- | Convert list of Pandoc inline elements to HTML.
950949inlineListToHtml :: PandocMonad m => WriterOptions -> [Inline] -> StateT WriterState m Html
951−inlineListToHtml opts lst =
952− mapM (inlineToHtml opts) lst >>= return . mconcat
950+inlineListToHtml opts lst = mconcat <$> mapM (inlineToHtml opts) lst
953951
954952-- | Annotates a MathML expression with the tex source
955953annotateMML :: XML.Element -> Text -> XML.Element
@@ -1011,37 +1009,36 @@ inlineToHtml opts inline = do
10111009 ]
10121010 ]
10131011
1014− (Emph lst) -> inlineListToHtml opts lst >>= return . H.em
1015− (Strong lst) -> inlineListToHtml opts lst >>= return . H.strong
1016− (Code attr@(ids,cs,kvs) str)
1012+ (Emph lst) -> H.em <$> inlineListToHtml opts lst
1013+ (Strong lst) -> H.strong <$> inlineListToHtml opts lst
1014+ (Code attr@(ids,cs,kvs) str)
10171015 -> case hlCode of
10181016 Left msg -> do
10191017 unless (T.null msg) $
10201018 report $ CouldNotHighlight msg
1021− addAttrs opts (ids,cs',kvs) $
1022− maybe H.code id sampOrVar $
1019+ addAttrs opts (ids,cs',kvs) $
1020+ fromMaybe H.code sampOrVar $
10231021 strToHtml str
10241022 Right h -> do
10251023 modify $ \st -> st{ stHighlighting = True }
1026− addAttrs opts (ids,[],kvs) $
1027− maybe id id sampOrVar $ h
1024+ addAttrs opts (ids,[],kvs) $
1025+ fromMaybe id sampOrVar h
10281026 where hlCode = if isJust (writerHighlightStyle opts)
10291027 then highlight
10301028 (writerSyntaxMap opts)
10311029 formatHtmlInline attr str
10321030 else Left ""
1033− (sampOrVar,cs') =
1034− if "sample" `elem` cs
1035− then (Just H.samp,"sample" `delete` cs)
1036− else if "variable" `elem` cs
1037− then (Just H.var,"variable" `delete` cs)
1038− else (Nothing,cs)
1039− (Strikeout lst) -> inlineListToHtml opts lst >>=
1040− return . H.del
1041− (SmallCaps lst) -> inlineListToHtml opts lst >>=
1042− return . (H.span ! A.class_ "smallcaps")
1043− (Superscript lst) -> inlineListToHtml opts lst >>= return . H.sup
1044− (Subscript lst) -> inlineListToHtml opts lst >>= return . H.sub
1031+ (sampOrVar,cs')
1032+ | "sample" `elem` cs =
1033+ (Just H.samp,"sample" `delete` cs)
1034+ | "variable" `elem` cs =
1035+ (Just H.var,"variable" `delete` cs)
1036+ | otherwise = (Nothing,cs)
1037+ (Strikeout lst) -> H.del <$> inlineListToHtml opts lst
1038+ (SmallCaps lst) -> (H.span ! A.class_ "smallcaps") <$>
1039+ inlineListToHtml opts lst
1040+ (Superscript lst) -> H.sup <$> inlineListToHtml opts lst
1041+ (Subscript lst) -> H.sub <$> inlineListToHtml opts lst
10451042 (Quoted quoteType lst) ->
10461043 let (leftQuote, rightQuote) = case quoteType of
10471044 SingleQuote -> (strToHtml "‘",
@@ -1210,7 +1207,7 @@ blockListToNote opts ref blocks = do
12101207 html5 <- gets stHtml5
12111208 -- If last block is Para or Plain, include the backlink at the end of
12121209 -- 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]
12141211 let backlink = [Link ("",["footnote-back"],kvs)
12151212 [Str "↩"] ("#" <> "fnref" <> ref,"")]
12161213 let blocks' = if null blocks