@@ -1353,6 +1353,48 @@ convertWithOpts opts args = do
13531353 , readerFileScope = fileScope
13541354 }
13551355
1356+ let writerOptions = def { writerTemplate = templ,
1357+ writerVariables = variables'',
1358+ writerTabStop = tabStop,
1359+ writerTableOfContents = toc,
1360+ writerHTMLMathMethod = mathMethod,
1361+ writerIncremental = incremental,
1362+ writerCiteMethod = citeMethod,
1363+ writerIgnoreNotes = False,
1364+ writerNumberSections = numberSections,
1365+ writerNumberOffset = numberFrom,
1366+ writerSectionDivs = sectionDivs,
1367+ writerReferenceLinks = referenceLinks,
1368+ writerReferenceLocation = referenceLocation,
1369+ writerDpi = dpi,
1370+ writerWrapText = wrap,
1371+ writerColumns = columns,
1372+ writerEmailObfuscation = obfuscationMethod,
1373+ writerIdentifierPrefix = idPrefix,
1374+ writerSourceURL = sourceURL,
1375+ writerUserDataDir = datadir,
1376+ writerHtml5 = html5,
1377+ writerHtmlQTags = htmlQTags,
1378+ writerTopLevelDivision = topLevelDivision,
1379+ writerListings = listings,
1380+ writerBeamer = False,
1381+ writerSlideLevel = slideLevel,
1382+ writerHighlight = highlight,
1383+ writerHighlightStyle = highlightStyle,
1384+ writerSetextHeaders = setextHeaders,
1385+ writerTeXLigatures = texLigatures,
1386+ writerEpubMetadata = epubMetadata,
1387+ writerEpubStylesheet = epubStylesheet,
1388+ writerEpubFonts = epubFonts,
1389+ writerEpubChapterLevel = epubChapterLevel,
1390+ writerTOCDepth = epubTOCDepth,
1391+ writerReferenceDoc = referenceDoc,
1392+ writerMediaBag = mempty,
1393+ writerVerbose = verbose,
1394+ writerLaTeXArgs = latexEngineArgs
1395+ }
1396+
1397+
13561398#ifdef _WINDOWS
13571399 let istty = True
13581400#else
@@ -1426,47 +1468,6 @@ convertWithOpts opts args = do
14261468 _ -> do pairs <- mapM (\s -> sourceToDoc [s]) sources
14271469 return (mconcat $ map fst pairs, mconcat $ map snd pairs)
14281470
1429− let writerOptions = def { writerTemplate = templ,
1430− writerVariables = variables'',
1431− writerTabStop = tabStop,
1432− writerTableOfContents = toc,
1433− writerHTMLMathMethod = mathMethod,
1434− writerIncremental = incremental,
1435− writerCiteMethod = citeMethod,
1436− writerIgnoreNotes = False,
1437− writerNumberSections = numberSections,
1438− writerNumberOffset = numberFrom,
1439− writerSectionDivs = sectionDivs,
1440− writerReferenceLinks = referenceLinks,
1441− writerReferenceLocation = referenceLocation,
1442− writerDpi = dpi,
1443− writerWrapText = wrap,
1444− writerColumns = columns,
1445− writerEmailObfuscation = obfuscationMethod,
1446− writerIdentifierPrefix = idPrefix,
1447− writerSourceURL = sourceURL,
1448− writerUserDataDir = datadir,
1449− writerHtml5 = html5,
1450− writerHtmlQTags = htmlQTags,
1451− writerTopLevelDivision = topLevelDivision,
1452− writerListings = listings,
1453− writerBeamer = False,
1454− writerSlideLevel = slideLevel,
1455− writerHighlight = highlight,
1456− writerHighlightStyle = highlightStyle,
1457− writerSetextHeaders = setextHeaders,
1458− writerTeXLigatures = texLigatures,
1459− writerEpubMetadata = epubMetadata,
1460− writerEpubStylesheet = epubStylesheet,
1461− writerEpubFonts = epubFonts,
1462− writerEpubChapterLevel = epubChapterLevel,
1463− writerTOCDepth = epubTOCDepth,
1464− writerReferenceDoc = referenceDoc,
1465− writerMediaBag = media,
1466− writerVerbose = verbose,
1467− writerLaTeXArgs = latexEngineArgs
1468− }
1469−
14701471
14711472 doc' <- (maybe return (extractMedia media) mbExtractMedia >=>
14721473 adjustMetadata metadata >=>
@@ -1481,9 +1482,10 @@ convertWithOpts opts args = do
14811482 writerFn "-" = UTF8.putStr
14821483 writerFn f = UTF8.writeFile f
14831484
1485+ let writerOptions' = writerOptions{ writerMediaBag = media }
14841486 case writer of
14851487 -- StringWriter f -> f writerOptions doc' >>= writerFn outputFile
1486− ByteStringWriter f -> (runIO' $ f writerOptions doc')
1488+ ByteStringWriter f -> (runIO' $ f writerOptions' doc')
14871489 >>= writeFnBinary outputFile
14881490 StringWriter f
14891491 | pdfOutput -> do
@@ -1502,7 +1504,7 @@ convertWithOpts opts args = do
15021504 err 41 $ pdfprog ++ " not found. " ++
15031505 pdfprog ++ " is needed for pdf output."
15041506
1505− res <- makePDF pdfprog f writerOptions doc'
1507+ res <- makePDF pdfprog f writerOptions' doc'
15061508 case res of
15071509 Right pdf -> writeFnBinary outputFile pdf
15081510 Left err' -> do
@@ -1513,10 +1515,10 @@ convertWithOpts opts args = do
15131515 let htmlFormat = format `elem`
15141516 ["html","html5","s5","slidy","slideous","dzslides","revealjs"]
15151517 selfcontain = if selfContained && htmlFormat
1516− then makeSelfContained writerOptions
1518+ then makeSelfContained writerOptions'
15171519 else return
15181520 handleEntities = if htmlFormat && ascii
15191521 then toEntities
15201522 else id
1521− output <- runIO' $ f writerOptions doc'
1523+ output <- runIO' $ f writerOptions' doc'
15221524 selfcontain (output ++ ['\n' | not standalone']) >>= writerFn outputFile . handleEntities