git.iko.soy/typeable/pandoc
on master help sign in
Implement `--default-image-extension` for LaTeX reader.
8dfbe3bJohn MacFarlane
README+4−3
@@ -244,9 +244,10 @@ Reader options
244 by spaces or commas.
244 by spaces or commas.
245
245
246`--default-image-extension=`*EXTENSION*
246`--default-image-extension=`*EXTENSION*
247−: Specify a default extension to use when markdown image paths/URLs have no
247+: Specify a default extension to use when image paths/URLs have no
248− extension. This allows you to use the same markdown source for
248+ extension. This allows you to use the same source for formats that
249− formats that require different kinds of images.
249+ require different kinds of images. Currently this option only affects
250+ the markdown and LaTeX readers.
250
251
251`--normalize`
252`--normalize`
252: Normalize the document after reading: merge adjacent
253: Normalize the document after reading: merge adjacent
src/Text/Pandoc/Readers/LaTeX.hs+10−2
@@ -51,6 +51,7 @@ import System.FilePath (replaceExtension, (</>))
51import Data.List (intercalate)
51import Data.List (intercalate)
52import qualified Data.Map as M
52import qualified Data.Map as M
53import qualified Control.Exception as E
53import qualified Control.Exception as E
54+import System.FilePath (takeExtension, addExtension)
54
55
55-- | Parse LaTeX from string and return 'Pandoc' document.
56-- | Parse LaTeX from string and return 'Pandoc' document.
56readLaTeX :: ReaderOptions -- ^ Reader options
57readLaTeX :: ReaderOptions -- ^ Reader options
@@ -430,8 +431,7 @@ inlineCommands = M.fromList $
430 , ("href", (unescapeURL <$> braced <* optional sp) >>= \url ->
431 , ("href", (unescapeURL <$> braced <* optional sp) >>= \url ->
431 tok >>= \lab ->
432 tok >>= \lab ->
432 pure (link url "" lab))
433 pure (link url "" lab))
433− , ("includegraphics", skipopts *> (unescapeURL <$> braced) >>=
434+ , ("includegraphics", skipopts *> (unescapeURL <$> braced) >>= mkImage)
434− (\src -> pure (image src "" (str "image"))))
435 , ("enquote", enquote)
435 , ("enquote", enquote)
436 , ("cite", citation "cite" AuthorInText False)
436 , ("cite", citation "cite" AuthorInText False)
437 , ("citep", citation "citep" NormalCitation False)
437 , ("citep", citation "citep" NormalCitation False)
@@ -488,6 +488,14 @@ inlineCommands = M.fromList $
488 -- in which case they will appear as raw latex blocks:
488 -- in which case they will appear as raw latex blocks:
489 [ "noindent", "index", "nocite" ]
489 [ "noindent", "index", "nocite" ]
490
490
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+
491inNote :: Inlines -> Inlines
499inNote :: Inlines -> Inlines
492inNote ils =
500inNote ils =
493 note $ para $ ils <> str "."
501 note $ para $ ils <> str "."