diff options
author | John MacFarlane <jgm@berkeley.edu> | 2019-07-20 10:17:07 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2019-07-20 10:17:49 -0700 |
commit | 465eeece6b5dcf74408d2f6ec45cf721307e9971 (patch) | |
tree | 6911c8ad3c6fd1892c6adbf059c5c7869f8d46fc /src/Text/Pandoc/Readers | |
parent | 3edee7f68cccb7ec14f06dd7510c1bff90f4db27 (diff) | |
download | pandoc-465eeece6b5dcf74408d2f6ec45cf721307e9971.tar.gz |
LaTeX reader: search for image with list of extensions...
like latex does, if an extension is not provided.
Closes #4933.
Diffstat (limited to 'src/Text/Pandoc/Readers')
-rw-r--r-- | src/Text/Pandoc/Readers/LaTeX.hs | 22 |
1 files changed, 16 insertions, 6 deletions
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 = |