Added --default-image-extension
and readerDefaultImageExtension
.
Note: Currently this only affects the markdown reader.
This commit is contained in:
parent
1aa74199cf
commit
c5f1a8ad2d
4 changed files with 134 additions and 112 deletions
5
README
5
README
|
@ -243,6 +243,11 @@ Reader options
|
||||||
`perl,numberLines` or `haskell`. Multiple classes may be separated
|
`perl,numberLines` or `haskell`. Multiple classes may be separated
|
||||||
by spaces or commas.
|
by spaces or commas.
|
||||||
|
|
||||||
|
`--default-image-extension=`*EXTENSION*
|
||||||
|
: Specify a default extension to use when markdown image paths/URLs have no
|
||||||
|
extension. This allows you to use the same markdown source for
|
||||||
|
formats that require different kinds of images.
|
||||||
|
|
||||||
`--normalize`
|
`--normalize`
|
||||||
: Normalize the document after reading: merge adjacent
|
: Normalize the document after reading: merge adjacent
|
||||||
`Str` or `Emph` elements, for example, and remove repeated `Space`s.
|
`Str` or `Emph` elements, for example, and remove repeated `Space`s.
|
||||||
|
|
208
pandoc.hs
208
pandoc.hs
|
@ -137,61 +137,63 @@ data Opt = Opt
|
||||||
, optSetextHeaders :: Bool -- ^ Use atx headers for markdown level 1-2
|
, optSetextHeaders :: Bool -- ^ Use atx headers for markdown level 1-2
|
||||||
, optAscii :: Bool -- ^ Use ascii characters only in html
|
, optAscii :: Bool -- ^ Use ascii characters only in html
|
||||||
, optTeXLigatures :: Bool -- ^ Use TeX ligatures for quotes/dashes
|
, optTeXLigatures :: Bool -- ^ Use TeX ligatures for quotes/dashes
|
||||||
|
, optDefaultImageExtension :: String -- ^ Default image extension
|
||||||
}
|
}
|
||||||
|
|
||||||
-- | Defaults for command-line options.
|
-- | Defaults for command-line options.
|
||||||
defaultOpts :: Opt
|
defaultOpts :: Opt
|
||||||
defaultOpts = Opt
|
defaultOpts = Opt
|
||||||
{ optTabStop = 4
|
{ optTabStop = 4
|
||||||
, optPreserveTabs = False
|
, optPreserveTabs = False
|
||||||
, optStandalone = False
|
, optStandalone = False
|
||||||
, optReader = "" -- null for default reader
|
, optReader = "" -- null for default reader
|
||||||
, optWriter = "" -- null for default writer
|
, optWriter = "" -- null for default writer
|
||||||
, optParseRaw = False
|
, optParseRaw = False
|
||||||
, optTableOfContents = False
|
, optTableOfContents = False
|
||||||
, optTransforms = []
|
, optTransforms = []
|
||||||
, optTemplate = Nothing
|
, optTemplate = Nothing
|
||||||
, optVariables = []
|
, optVariables = []
|
||||||
, optOutputFile = "-" -- "-" means stdout
|
, optOutputFile = "-" -- "-" means stdout
|
||||||
, optNumberSections = False
|
, optNumberSections = False
|
||||||
, optSectionDivs = False
|
, optSectionDivs = False
|
||||||
, optIncremental = False
|
, optIncremental = False
|
||||||
, optSelfContained = False
|
, optSelfContained = False
|
||||||
, optSmart = False
|
, optSmart = False
|
||||||
, optOldDashes = False
|
, optOldDashes = False
|
||||||
, optHtml5 = False
|
, optHtml5 = False
|
||||||
, optHtmlQTags = False
|
, optHtmlQTags = False
|
||||||
, optHighlight = True
|
, optHighlight = True
|
||||||
, optHighlightStyle = pygments
|
, optHighlightStyle = pygments
|
||||||
, optChapters = False
|
, optChapters = False
|
||||||
, optHTMLMathMethod = PlainMath
|
, optHTMLMathMethod = PlainMath
|
||||||
, optReferenceODT = Nothing
|
, optReferenceODT = Nothing
|
||||||
, optReferenceDocx = Nothing
|
, optReferenceDocx = Nothing
|
||||||
, optEpubStylesheet = Nothing
|
, optEpubStylesheet = Nothing
|
||||||
, optEpubMetadata = ""
|
, optEpubMetadata = ""
|
||||||
, optEpubFonts = []
|
, optEpubFonts = []
|
||||||
, optEpubChapterLevel = 1
|
, optEpubChapterLevel = 1
|
||||||
, optTOCDepth = 3
|
, optTOCDepth = 3
|
||||||
, optDumpArgs = False
|
, optDumpArgs = False
|
||||||
, optIgnoreArgs = False
|
, optIgnoreArgs = False
|
||||||
, optReferenceLinks = False
|
, optReferenceLinks = False
|
||||||
, optWrapText = True
|
, optWrapText = True
|
||||||
, optColumns = 72
|
, optColumns = 72
|
||||||
, optPlugins = []
|
, optPlugins = []
|
||||||
, optEmailObfuscation = JavascriptObfuscation
|
, optEmailObfuscation = JavascriptObfuscation
|
||||||
, optIdentifierPrefix = ""
|
, optIdentifierPrefix = ""
|
||||||
, optIndentedCodeClasses = []
|
, optIndentedCodeClasses = []
|
||||||
, optDataDir = Nothing
|
, optDataDir = Nothing
|
||||||
, optCiteMethod = Citeproc
|
, optCiteMethod = Citeproc
|
||||||
, optBibliography = []
|
, optBibliography = []
|
||||||
, optCslFile = Nothing
|
, optCslFile = Nothing
|
||||||
, optAbbrevsFile = Nothing
|
, optAbbrevsFile = Nothing
|
||||||
, optListings = False
|
, optListings = False
|
||||||
, optLaTeXEngine = "pdflatex"
|
, optLaTeXEngine = "pdflatex"
|
||||||
, optSlideLevel = Nothing
|
, optSlideLevel = Nothing
|
||||||
, optSetextHeaders = True
|
, optSetextHeaders = True
|
||||||
, optAscii = False
|
, optAscii = False
|
||||||
, optTeXLigatures = True
|
, optTeXLigatures = True
|
||||||
|
, optDefaultImageExtension = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
-- | A list of functions, each transforming the options data structure
|
-- | A list of functions, each transforming the options data structure
|
||||||
|
@ -495,6 +497,12 @@ options =
|
||||||
(\opt -> return opt { optSectionDivs = True }))
|
(\opt -> return opt { optSectionDivs = True }))
|
||||||
"" -- "Put sections in div tags in HTML"
|
"" -- "Put sections in div tags in HTML"
|
||||||
|
|
||||||
|
, Option "" ["default-image-extension"]
|
||||||
|
(ReqArg
|
||||||
|
(\arg opt -> return opt { optDefaultImageExtension = arg })
|
||||||
|
"extension")
|
||||||
|
"" -- "Default extension for extensionless images"
|
||||||
|
|
||||||
, Option "" ["email-obfuscation"]
|
, Option "" ["email-obfuscation"]
|
||||||
(ReqArg
|
(ReqArg
|
||||||
(\arg opt -> do
|
(\arg opt -> do
|
||||||
|
@ -806,55 +814,56 @@ main = do
|
||||||
-- thread option data structure through all supplied option actions
|
-- thread option data structure through all supplied option actions
|
||||||
opts <- foldl (>>=) (return defaultOpts') actions
|
opts <- foldl (>>=) (return defaultOpts') actions
|
||||||
|
|
||||||
let Opt { optTabStop = tabStop
|
let Opt { optTabStop = tabStop
|
||||||
, optPreserveTabs = preserveTabs
|
, optPreserveTabs = preserveTabs
|
||||||
, optStandalone = standalone
|
, optStandalone = standalone
|
||||||
, optReader = readerName
|
, optReader = readerName
|
||||||
, optWriter = writerName
|
, optWriter = writerName
|
||||||
, optParseRaw = parseRaw
|
, optParseRaw = parseRaw
|
||||||
, optVariables = variables
|
, optVariables = variables
|
||||||
, optTableOfContents = toc
|
, optTableOfContents = toc
|
||||||
, optTransforms = transforms
|
, optTransforms = transforms
|
||||||
, optTemplate = templatePath
|
, optTemplate = templatePath
|
||||||
, optOutputFile = outputFile
|
, optOutputFile = outputFile
|
||||||
, optNumberSections = numberSections
|
, optNumberSections = numberSections
|
||||||
, optSectionDivs = sectionDivs
|
, optSectionDivs = sectionDivs
|
||||||
, optIncremental = incremental
|
, optIncremental = incremental
|
||||||
, optSelfContained = selfContained
|
, optSelfContained = selfContained
|
||||||
, optSmart = smart
|
, optSmart = smart
|
||||||
, optOldDashes = oldDashes
|
, optOldDashes = oldDashes
|
||||||
, optHtml5 = html5
|
, optHtml5 = html5
|
||||||
, optHtmlQTags = htmlQTags
|
, optHtmlQTags = htmlQTags
|
||||||
, optHighlight = highlight
|
, optHighlight = highlight
|
||||||
, optHighlightStyle = highlightStyle
|
, optHighlightStyle = highlightStyle
|
||||||
, optChapters = chapters
|
, optChapters = chapters
|
||||||
, optHTMLMathMethod = mathMethod
|
, optHTMLMathMethod = mathMethod
|
||||||
, optReferenceODT = referenceODT
|
, optReferenceODT = referenceODT
|
||||||
, optReferenceDocx = referenceDocx
|
, optReferenceDocx = referenceDocx
|
||||||
, optEpubStylesheet = epubStylesheet
|
, optEpubStylesheet = epubStylesheet
|
||||||
, optEpubMetadata = epubMetadata
|
, optEpubMetadata = epubMetadata
|
||||||
, optEpubFonts = epubFonts
|
, optEpubFonts = epubFonts
|
||||||
, optEpubChapterLevel = epubChapterLevel
|
, optEpubChapterLevel = epubChapterLevel
|
||||||
, optTOCDepth = epubTOCDepth
|
, optTOCDepth = epubTOCDepth
|
||||||
, optDumpArgs = dumpArgs
|
, optDumpArgs = dumpArgs
|
||||||
, optIgnoreArgs = ignoreArgs
|
, optIgnoreArgs = ignoreArgs
|
||||||
, optReferenceLinks = referenceLinks
|
, optReferenceLinks = referenceLinks
|
||||||
, optWrapText = wrap
|
, optWrapText = wrap
|
||||||
, optColumns = columns
|
, optColumns = columns
|
||||||
, optEmailObfuscation = obfuscationMethod
|
, optEmailObfuscation = obfuscationMethod
|
||||||
, optIdentifierPrefix = idPrefix
|
, optIdentifierPrefix = idPrefix
|
||||||
, optIndentedCodeClasses = codeBlockClasses
|
, optIndentedCodeClasses = codeBlockClasses
|
||||||
, optDataDir = mbDataDir
|
, optDataDir = mbDataDir
|
||||||
, optBibliography = reffiles
|
, optBibliography = reffiles
|
||||||
, optCslFile = mbCsl
|
, optCslFile = mbCsl
|
||||||
, optAbbrevsFile = cslabbrevs
|
, optAbbrevsFile = cslabbrevs
|
||||||
, optCiteMethod = citeMethod
|
, optCiteMethod = citeMethod
|
||||||
, optListings = listings
|
, optListings = listings
|
||||||
, optLaTeXEngine = latexEngine
|
, optLaTeXEngine = latexEngine
|
||||||
, optSlideLevel = slideLevel
|
, optSlideLevel = slideLevel
|
||||||
, optSetextHeaders = setextHeaders
|
, optSetextHeaders = setextHeaders
|
||||||
, optAscii = ascii
|
, optAscii = ascii
|
||||||
, optTeXLigatures = texLigatures
|
, optTeXLigatures = texLigatures
|
||||||
|
, optDefaultImageExtension = defaultImageExtension
|
||||||
} = opts
|
} = opts
|
||||||
|
|
||||||
when dumpArgs $
|
when dumpArgs $
|
||||||
|
@ -996,6 +1005,7 @@ main = do
|
||||||
, readerCitationStyle = mbsty
|
, readerCitationStyle = mbsty
|
||||||
, readerIndentedCodeClasses = codeBlockClasses
|
, readerIndentedCodeClasses = codeBlockClasses
|
||||||
, readerApplyMacros = not laTeXOutput
|
, readerApplyMacros = not laTeXOutput
|
||||||
|
, readerDefaultImageExtension = defaultImageExtension
|
||||||
}
|
}
|
||||||
|
|
||||||
let writerOptions = def { writerStandalone = standalone',
|
let writerOptions = def { writerStandalone = standalone',
|
||||||
|
|
|
@ -204,22 +204,24 @@ data ReaderOptions = ReaderOptions{
|
||||||
, readerApplyMacros :: Bool -- ^ Apply macros to TeX math
|
, readerApplyMacros :: Bool -- ^ Apply macros to TeX math
|
||||||
, readerIndentedCodeClasses :: [String] -- ^ Default classes for
|
, readerIndentedCodeClasses :: [String] -- ^ Default classes for
|
||||||
-- indented code blocks
|
-- indented code blocks
|
||||||
|
, readerDefaultImageExtension :: String -- ^ Default extension for images
|
||||||
} deriving (Show, Read)
|
} deriving (Show, Read)
|
||||||
|
|
||||||
instance Default ReaderOptions
|
instance Default ReaderOptions
|
||||||
where def = ReaderOptions{
|
where def = ReaderOptions{
|
||||||
readerExtensions = pandocExtensions
|
readerExtensions = pandocExtensions
|
||||||
, readerSmart = False
|
, readerSmart = False
|
||||||
, readerStrict = False
|
, readerStrict = False
|
||||||
, readerStandalone = False
|
, readerStandalone = False
|
||||||
, readerParseRaw = False
|
, readerParseRaw = False
|
||||||
, readerColumns = 80
|
, readerColumns = 80
|
||||||
, readerTabStop = 4
|
, readerTabStop = 4
|
||||||
, readerOldDashes = False
|
, readerOldDashes = False
|
||||||
, readerReferences = []
|
, readerReferences = []
|
||||||
, readerCitationStyle = Nothing
|
, readerCitationStyle = Nothing
|
||||||
, readerApplyMacros = True
|
, readerApplyMacros = True
|
||||||
, readerIndentedCodeClasses = []
|
, readerIndentedCodeClasses = []
|
||||||
|
, readerDefaultImageExtension = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
--
|
--
|
||||||
|
|
|
@ -51,6 +51,7 @@ import qualified Text.CSL as CSL
|
||||||
import Data.Monoid (mconcat, mempty)
|
import Data.Monoid (mconcat, mempty)
|
||||||
import Control.Applicative ((<$>), (<*), (*>), (<$))
|
import Control.Applicative ((<$>), (<*), (*>), (<$))
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
|
import System.FilePath (takeExtension, addExtension)
|
||||||
import Text.HTML.TagSoup
|
import Text.HTML.TagSoup
|
||||||
import Text.HTML.TagSoup.Match (tagOpen)
|
import Text.HTML.TagSoup.Match (tagOpen)
|
||||||
import qualified Data.Set as Set
|
import qualified Data.Set as Set
|
||||||
|
@ -1561,7 +1562,11 @@ image :: MarkdownParser (F Inlines)
|
||||||
image = try $ do
|
image = try $ do
|
||||||
char '!'
|
char '!'
|
||||||
(lab,raw) <- reference
|
(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 :: MarkdownParser (F Inlines)
|
||||||
note = try $ do
|
note = try $ do
|
||||||
|
|
Loading…
Reference in a new issue