git.iko.soy/typeable/pandoc
on master help sign in
HTML writer: make sure html4, html5 formats work for raw blocks/inlines.
commitda7d9ef295de3d51db97c4ff57104ae7d6e57e86 authorJohn MacFarlane <jgm@berkeley.edu> dateFri 23 Jun 2017, 11:51 (9 years ago) parent595d81b
1 file changed+26−14
src/Text/Pandoc/Writers/HTML.hs+26−14
src/Text/Pandoc/Writers/HTML.hs+26−14
@@ -603,7 +603,8 @@ blockToHtml opts (Para lst)
603603 contents <- inlineListToHtml opts lst
604604 return $ H.p contents
605605 where
606− isEmptyRaw [RawInline f _] = f /= (Format "html")
606+ isEmptyRaw [RawInline f _] = f `notElem` [Format "html",
607+ Format "html4", Format "html5"]
607608 isEmptyRaw _ = False
608609blockToHtml opts (LineBlock lns) =
609610 if writerWrapText opts == WrapNone
@@ -632,14 +633,17 @@ blockToHtml opts (Div attr@(ident, classes, kvs) bs) = do
632633 NoSlides -> addAttrs opts' attr $ H.div $ contents'
633634 _ -> mempty
634635 else addAttrs opts (ident, classes', kvs) $ divtag $ contents'
635−blockToHtml opts (RawBlock f str)
636− | f == Format "html" = return $ preEscapedString str
637− | (f == Format "latex" || f == Format "tex") &&
638− allowsMathEnvironments (writerHTMLMathMethod opts) &&
639− isMathEnvironment str = blockToHtml opts $ Plain [Math DisplayMath str]
640− | otherwise = do
641− report $ BlockNotRendered (RawBlock f str)
642− return mempty
636+blockToHtml opts (RawBlock f str) = do
637+ ishtml <- isRawHtml f
638+ if ishtml
639+ then return $ preEscapedString str
640+ else if (f == Format "latex" || f == Format "tex") &&
641+ allowsMathEnvironments (writerHTMLMathMethod opts) &&
642+ isMathEnvironment str
643+ then blockToHtml opts $ Plain [Math DisplayMath str]
644+ else do
645+ report $ BlockNotRendered (RawBlock f str)
646+ return mempty
643647blockToHtml _ (HorizontalRule) = do
644648 html5 <- gets stHtml5
645649 return $ if html5 then H5.hr else H.hr
@@ -977,11 +981,13 @@ inlineToHtml opts inline = do
977981 return $ case t of
978982 InlineMath -> m
979983 DisplayMath -> brtag >> m >> brtag
980− (RawInline f str)
981− | f == Format "html" -> return $ preEscapedString str
982− | otherwise -> do
983− report $ InlineNotRendered inline
984− return mempty
984+ (RawInline f str) -> do
985+ ishtml <- isRawHtml f
986+ if ishtml
987+ then return $ preEscapedString str
988+ else do
989+ report $ InlineNotRendered inline
990+ return mempty
985991 (Link attr txt (s,_)) | "mailto:" `isPrefixOf` s -> do
986992 linkText <- inlineListToHtml opts txt
987993 lift $ obfuscateLink opts attr linkText s
@@ -1129,3 +1135,9 @@ allowsMathEnvironments (MathJax _) = True
11291135allowsMathEnvironments (MathML) = True
11301136allowsMathEnvironments (WebTeX _) = True
11311137allowsMathEnvironments _ = False
1138+
1139+isRawHtml :: PandocMonad m => Format -> StateT WriterState m Bool
1140+isRawHtml f = do
1141+ html5 <- gets stHtml5
1142+ return $ f == Format "html" ||
1143+ ((html5 && f == Format "html5") || f == Format "html4")