diff options
author | John MacFarlane <jgm@berkeley.edu> | 2014-07-30 13:20:44 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2014-07-30 13:20:44 -0700 |
commit | 77aa72ec245e3f1918ac095697fb6e4a82484f36 (patch) | |
tree | 460b4a5eed00acf1e271eafd8cea0c82a65d3b84 | |
parent | 08e2498e7395621476145ecc262654450c935537 (diff) | |
download | pandoc-77aa72ec245e3f1918ac095697fb6e4a82484f36.tar.gz |
pandoc: Thread media bag into WriterOptions.
This will make it available to docx and epub readers, etc.,
so we don't have to extract media to a directory when going
from docx -> epub.
-rw-r--r-- | pandoc.hs | 26 |
1 files changed, 14 insertions, 12 deletions
@@ -1222,19 +1222,21 @@ main = do | src `elem` paths = Image lab (dir ++ "/" ++ src, tit) adjustImagePath _ _ x = x - doc <- case reader of - StringReader r-> - readSources sources >>= - handleIncludes' . convertTabs . intercalate "\n" >>= - r readerOpts + (doc, writerOptions') <- + case reader of + StringReader r-> do + inp <- readSources sources >>= + handleIncludes' . convertTabs . intercalate "\n" + d <- r readerOpts inp + return (d, writerOptions) ByteStringReader r -> do (d, media) <- readFiles sources >>= r readerOpts case mbExtractMedia of Just dir | not (M.null media) -> do mapM_ (writeMedia dir) $ M.toList media - return $ walk (adjustImagePath dir (M.keys media)) d - _ -> return d - + let d' = walk (adjustImagePath dir (M.keys media)) d + return (d', writerOptions{ writerMediaBag = media }) + _ -> return (d, writerOptions) let doc0 = M.foldWithKey setMeta doc metadata let doc1 = foldr ($) doc0 transforms @@ -1248,8 +1250,8 @@ main = do writerFn f = UTF8.writeFile f case writer of - IOStringWriter f -> f writerOptions doc2 >>= writerFn outputFile - IOByteStringWriter f -> f writerOptions doc2 >>= writeBinary + IOStringWriter f -> f writerOptions' doc2 >>= writerFn outputFile + IOByteStringWriter f -> f writerOptions' doc2 >>= writeBinary PureStringWriter f | pdfOutput -> do -- make sure writer is latex or beamer @@ -1263,14 +1265,14 @@ main = do err 41 $ latexEngine ++ " not found. " ++ latexEngine ++ " is needed for pdf output." - res <- makePDF latexEngine f writerOptions doc2 + res <- makePDF latexEngine f writerOptions' doc2 case res of Right pdf -> writeBinary pdf Left err' -> do B.hPutStr stderr $ err' B.hPut stderr $ B.pack [10] err 43 "Error producing PDF from TeX source" - | otherwise -> selfcontain (f writerOptions doc2 ++ + | otherwise -> selfcontain (f writerOptions' doc2 ++ ['\n' | not standalone']) >>= writerFn outputFile . handleEntities where htmlFormat = writerName' `elem` |