diff options
author | John MacFarlane <jgm@berkeley.edu> | 2011-07-16 10:11:04 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2011-07-16 10:11:46 -0700 |
commit | 8d13ff5bc3cff3c0ce0dc9455db9f7f29b384cdf (patch) | |
tree | 8523b48bbe8a765403dd607777af0aba9c244eaf /src/Text/Pandoc/Writers | |
parent | dd59cd23415e1fdf3286ea4d45a104e8c093717d (diff) | |
download | pandoc-8d13ff5bc3cff3c0ce0dc9455db9f7f29b384cdf.tar.gz |
HTML writer: Use embed tag for images with non-image extensions.
(e.g. PDFs).
Closes #264.
Diffstat (limited to 'src/Text/Pandoc/Writers')
-rw-r--r-- | src/Text/Pandoc/Writers/HTML.hs | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs index 93d90bea0..ae94f7696 100644 --- a/src/Text/Pandoc/Writers/HTML.hs +++ b/src/Text/Pandoc/Writers/HTML.hs @@ -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 |