HTML writer: Use embed tag for images with non-image extensions.

(e.g.  PDFs).

Closes #264.
This commit is contained in:
John MacFarlane 2011-07-16 10:11:04 -07:00
parent dd59cd2341
commit 8d13ff5bc3

View file

@ -46,6 +46,7 @@ import Text.XHtml.Transitional hiding ( stringToHtml, unordList, ordList )
import qualified Text.XHtml.Transitional as XHtml
import Text.TeXMath
import Text.XML.Light.Output
import System.FilePath (takeExtension)
data WriterState = WriterState
{ stNotes :: [Html] -- ^ List of notes
@ -320,6 +321,17 @@ attrsToHtml opts (id',classes',keyvals) =
[prefixedId opts id' | not (null id')] ++
map (\(x,y) -> strAttr x y) keyvals
imageExts :: [String]
imageExts = [ "art", "bmp", "cdr", "cdt", "cpt", "cr2", "crw", "djvu", "erf",
"gif", "ico", "ief", "jng", "jpg", "jpeg", "nef", "orf", "pat", "pbm",
"pcx", "pgm", "png", "pnm", "ppm", "psd", "ras", "rgb", "svg", "tiff",
"wbmp", "xbm", "xpm", "xwd" ]
treatAsImage :: FilePath -> Bool
treatAsImage fp =
let ext = map toLower $ drop 1 $ takeExtension fp
in null ext || ext `elem` imageExts
-- | Convert Pandoc block element to HTML.
blockToHtml :: WriterOptions -> Block -> State WriterState Html
blockToHtml _ Null = return noHtml
@ -603,7 +615,7 @@ inlineToHtml opts inline =
return $ anchor ! ([href s] ++
if null tit then [] else [title tit]) $
linkText
(Image txt (s,tit)) -> do
(Image txt (s,tit)) | treatAsImage s -> do
let alternate' = stringify txt
let attributes = [src s] ++
(if null tit
@ -614,6 +626,13 @@ inlineToHtml opts inline =
else [alt alternate']
return $ image ! attributes
-- note: null title included, as in Markdown.pl
(Image _ (s,tit)) -> do
let attributes = [src s] ++
(if null tit
then []
else [title tit])
return $ itag "embed" ! attributes
-- note: null title included, as in Markdown.pl
(Note contents) -> do
st <- get
let notes = stNotes st