git.iko.soy/typeable/pandoc
on master help sign in
Implement `--default-image-extension` for LaTeX reader.
commit8dfbe3bbe8155c82123028985b380ce9abdc4fa9 authorJohn MacFarlane <fiddlosopher@gmail.com> dateWed 6 Feb 2013, 08:36 (14 years ago) parent1a2eea2
2 files changed+14−5
README+4−3 src/Text/Pandoc/Readers/LaTeX.hs+10−2
README+4−3
@@ -244,9 +244,10 @@ Reader options
244244 by spaces or commas.
245245
246246`--default-image-extension=`*EXTENSION*
247−: Specify a default extension to use when markdown image paths/URLs have no
248− extension. This allows you to use the same markdown source for
249− formats that require different kinds of images.
247+: Specify a default extension to use when image paths/URLs have no
248+ extension. This allows you to use the same source for formats that
249+ require different kinds of images. Currently this option only affects
250+ the markdown and LaTeX readers.
250251
251252`--normalize`
252253: Normalize the document after reading: merge adjacent
src/Text/Pandoc/Readers/LaTeX.hs+10−2
@@ -51,6 +51,7 @@ import System.FilePath (replaceExtension, (</>))
5151import Data.List (intercalate)
5252import qualified Data.Map as M
5353import qualified Control.Exception as E
54+import System.FilePath (takeExtension, addExtension)
5455
5556-- | Parse LaTeX from string and return 'Pandoc' document.
5657readLaTeX :: ReaderOptions -- ^ Reader options
@@ -430,8 +431,7 @@ inlineCommands = M.fromList $
430431 , ("href", (unescapeURL <$> braced <* optional sp) >>= \url ->
431432 tok >>= \lab ->
432433 pure (link url "" lab))
433− , ("includegraphics", skipopts *> (unescapeURL <$> braced) >>=
434− (\src -> pure (image src "" (str "image"))))
434+ , ("includegraphics", skipopts *> (unescapeURL <$> braced) >>= mkImage)
435435 , ("enquote", enquote)
436436 , ("cite", citation "cite" AuthorInText False)
437437 , ("citep", citation "citep" NormalCitation False)
@@ -488,6 +488,14 @@ inlineCommands = M.fromList $
488488 -- in which case they will appear as raw latex blocks:
489489 [ "noindent", "index", "nocite" ]
490490
491+mkImage :: String -> LP Inlines
492+mkImage src =
493+ case takeExtension src of
494+ "" -> do
495+ defaultExt <- getOption readerDefaultImageExtension
496+ return $ image (addExtension src defaultExt) "" (str "image")
497+ _ -> return $ image src "" (str "image")
498+
491499inNote :: Inlines -> Inlines
492500inNote ils =
493501 note $ para $ ils <> str "."