From c5f1a8ad2d2f7972e2c3e8bd22686bb99e84356d Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 5 Feb 2013 20:08:00 -0800 Subject: Added `--default-image-extension` and `readerDefaultImageExtension`. Note: Currently this only affects the markdown reader. --- src/Text/Pandoc/Options.hs | 26 ++++++++++++++------------ src/Text/Pandoc/Readers/Markdown.hs | 7 ++++++- 2 files changed, 20 insertions(+), 13 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Options.hs b/src/Text/Pandoc/Options.hs index f67debf97..1ba8a6dd6 100644 --- a/src/Text/Pandoc/Options.hs +++ b/src/Text/Pandoc/Options.hs @@ -204,22 +204,24 @@ data ReaderOptions = ReaderOptions{ , readerApplyMacros :: Bool -- ^ Apply macros to TeX math , readerIndentedCodeClasses :: [String] -- ^ Default classes for -- indented code blocks + , readerDefaultImageExtension :: String -- ^ Default extension for images } deriving (Show, Read) instance Default ReaderOptions where def = ReaderOptions{ - readerExtensions = pandocExtensions - , readerSmart = False - , readerStrict = False - , readerStandalone = False - , readerParseRaw = False - , readerColumns = 80 - , readerTabStop = 4 - , readerOldDashes = False - , readerReferences = [] - , readerCitationStyle = Nothing - , readerApplyMacros = True - , readerIndentedCodeClasses = [] + readerExtensions = pandocExtensions + , readerSmart = False + , readerStrict = False + , readerStandalone = False + , readerParseRaw = False + , readerColumns = 80 + , readerTabStop = 4 + , readerOldDashes = False + , readerReferences = [] + , readerCitationStyle = Nothing + , readerApplyMacros = True + , readerIndentedCodeClasses = [] + , readerDefaultImageExtension = "" } -- diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index dc30e17ed..6b144f35e 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -51,6 +51,7 @@ import qualified Text.CSL as CSL import Data.Monoid (mconcat, mempty) import Control.Applicative ((<$>), (<*), (*>), (<$)) import Control.Monad +import System.FilePath (takeExtension, addExtension) import Text.HTML.TagSoup import Text.HTML.TagSoup.Match (tagOpen) import qualified Data.Set as Set @@ -1561,7 +1562,11 @@ image :: MarkdownParser (F Inlines) image = try $ do char '!' (lab,raw) <- reference - regLink B.image lab <|> referenceLink B.image (lab,raw) + defaultExt <- getOption readerDefaultImageExtension + let constructor src = case takeExtension src of + "" -> B.image (addExtension src defaultExt) + _ -> B.image src + regLink constructor lab <|> referenceLink constructor (lab,raw) note :: MarkdownParser (F Inlines) note = try $ do -- cgit v1.2.3