From 465eeece6b5dcf74408d2f6ec45cf721307e9971 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 20 Jul 2019 10:17:07 -0700 Subject: LaTeX reader: search for image with list of extensions... like latex does, if an extension is not provided. Closes #4933. --- src/Text/Pandoc/Readers/LaTeX.hs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 73780a8b8..fe677e470 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -43,7 +43,7 @@ import Text.Pandoc.BCP47 (Lang (..), renderLang) import Text.Pandoc.Builder import Text.Pandoc.Class (PandocMonad, PandocPure, getResourcePath, lookupEnv, readFileFromDirs, report, setResourcePath, - setTranslations, translateTerm, trace) + setTranslations, translateTerm, trace, fileExists) import Text.Pandoc.Error (PandocError ( PandocParseError, PandocParsecError)) import Text.Pandoc.Highlighting (fromListingsLanguage, languagesByExtension) import Text.Pandoc.ImageSize (numUnit, showFl) @@ -205,11 +205,21 @@ mkImage options src = do $ filter (\(k,_) -> k `elem` ["width", "height"]) options let attr = ("",[], kvs) let alt = str "image" - case takeExtension src of - "" -> do - defaultExt <- getOption readerDefaultImageExtension - return $ imageWith attr (addExtension src defaultExt) "" alt - _ -> return $ imageWith attr src "" alt + defaultExt <- getOption readerDefaultImageExtension + let exts' = [".pdf", ".png", ".jpg", ".mps", ".jpeg", ".jbig2", ".jb2"] + let exts = exts' ++ map (map toUpper) exts' + let findFile s [] = return s + findFile s (e:es) = do + let s' = addExtension s e + exists <- fileExists s' + if exists + then return s' + else findFile s es + src' <- case takeExtension src of + "" | not (null defaultExt) -> return $ addExtension src defaultExt + | otherwise -> findFile src exts + _ -> return src + return $ imageWith attr src' "" alt doxspace :: PandocMonad m => LP m Inlines doxspace = -- cgit v1.2.3