git.iko.soy/typeable/pandoc
on master help sign in
LaTeX reader: search for image with list of extensions...
465eeecJohn MacFarlane
src/Text/Pandoc/Readers/LaTeX.hs+16−6
@@ -43,7 +43,7 @@ import Text.Pandoc.BCP47 (Lang (..), renderLang)
43import Text.Pandoc.Builder
43import Text.Pandoc.Builder
44import Text.Pandoc.Class (PandocMonad, PandocPure, getResourcePath, lookupEnv,
44import Text.Pandoc.Class (PandocMonad, PandocPure, getResourcePath, lookupEnv,
45 readFileFromDirs, report, setResourcePath,
45 readFileFromDirs, report, setResourcePath,
46− setTranslations, translateTerm, trace)
46+ setTranslations, translateTerm, trace, fileExists)
47import Text.Pandoc.Error (PandocError ( PandocParseError, PandocParsecError))
47import Text.Pandoc.Error (PandocError ( PandocParseError, PandocParsecError))
48import Text.Pandoc.Highlighting (fromListingsLanguage, languagesByExtension)
48import Text.Pandoc.Highlighting (fromListingsLanguage, languagesByExtension)
49import Text.Pandoc.ImageSize (numUnit, showFl)
49import Text.Pandoc.ImageSize (numUnit, showFl)
@@ -205,11 +205,21 @@ mkImage options src = do
205 $ filter (\(k,_) -> k `elem` ["width", "height"]) options
205 $ filter (\(k,_) -> k `elem` ["width", "height"]) options
206 let attr = ("",[], kvs)
206 let attr = ("",[], kvs)
207 let alt = str "image"
207 let alt = str "image"
208+ defaultExt <- getOption readerDefaultImageExtension
209+ let exts' = [".pdf", ".png", ".jpg", ".mps", ".jpeg", ".jbig2", ".jb2"]
210+ let exts = exts' ++ map (map toUpper) exts'
211+ let findFile s [] = return s
212+ findFile s (e:es) = do
213+ let s' = addExtension s e
214+ exists <- fileExists s'
215+ if exists
216+ then return s'
217+ else findFile s es
208− case takeExtension src of
218+ src' <- case takeExtension src of
209− "" -> do
210− defaultExt <- getOption readerDefaultImageExtension
211− return $ imageWith attr (addExtension src defaultExt) "" alt
219+ "" | not (null defaultExt) -> return $ addExtension src defaultExt
220+ | otherwise -> findFile src exts
221+ _ -> return src
212− _ -> return $ imageWith attr src "" alt
222+ return $ imageWith attr src' "" alt
213
223
214doxspace :: PandocMonad m => LP m Inlines
224doxspace :: PandocMonad m => LP m Inlines
215doxspace =
225doxspace =
test/command/4933.mdnew file+6
@@ -0,0 +1,6 @@
1+```
2+% pandoc -f latex -t native
3+\includegraphics{lalune}
4+^D
5+[Para [Image ("",[],[]) [Str "image"] ("lalune.jpg","")]]
6+```