Skip to content

Commit 7a4f709

Browse files
committed
[WIP] Move resource embedding into HTML writer
1 parent 790abcf commit 7a4f709

File tree

5 files changed

+17
-6
lines changed

5 files changed

+17
-6
lines changed

pandoc-lua-engine/src/Text/Pandoc/Lua/Marshal/WriterOptions.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ typeWriterOptions = deftype "WriterOptions"
8080
(pushViaJSON, writerEmailObfuscation)
8181
(peekViaJSON, \opts x -> opts{ writerEmailObfuscation = x })
8282

83+
, property "embed_resources"
84+
"Whether resources should be embedded in HTML output"
85+
(pushViaJSON, writerEmbedResources)
86+
(peekViaJSON, \opts x -> opts{ writerEmbedResources = x })
87+
8388
, property "split_level"
8489
"Level at which EPUB or chunked HTML documents are split into files"
8590
(pushIntegral, writerSplitLevel)

src/Text/Pandoc/App.hs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,7 @@ convertWithOpts' scriptingEngine istty datadir opts = do
330330
| T.null t || T.last t /= '\n' = t <> T.singleton '\n'
331331
| otherwise = t
332332
textOutput <- ensureNl <$> f writerOptions doc
333-
if (optSelfContained opts || optEmbedResources opts) && htmlFormat format
334-
then TextOutput <$> makeSelfContained textOutput
335-
else return $ TextOutput textOutput
333+
return $ TextOutput textOutput
336334
reports <- getLog
337335
return (output, reports)
338336

src/Text/Pandoc/App/OutputSettings.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ optToOutputSettings scriptingEngine opts = do
263263
, writerSyntaxMap = syntaxMap
264264
, writerPreferAscii = optAscii opts
265265
, writerLinkImages = optLinkImages opts
266+
, writerEmbedResources = optEmbedResources opts ||
267+
optSelfContained opts
266268
}
267269
return $ OutputSettings
268270
{ outputFormat = format

src/Text/Pandoc/Options.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ data WriterOptions = WriterOptions
326326
, writerSyntaxMap :: SyntaxMap
327327
, writerPreferAscii :: Bool -- ^ Prefer ASCII representations of characters when possible
328328
, writerLinkImages :: Bool -- ^ Use links rather than embedding ODT images
329+
, writerEmbedResources :: Bool -- ^ Embed resources in HTML
329330
} deriving (Show, Data, Typeable, Generic)
330331

331332
instance Default WriterOptions where
@@ -365,6 +366,7 @@ instance Default WriterOptions where
365366
, writerSyntaxMap = defaultSyntaxMap
366367
, writerPreferAscii = False
367368
, writerLinkImages = False
369+
, writerEmbedResources = False
368370
}
369371

370372
instance HasSyntaxExtensions WriterOptions where

src/Text/Pandoc/Writers/HTML.hs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import Text.Pandoc.Highlighting (formatHtmlBlock, formatHtml4Block,
5555
formatHtmlInline, highlight, styleToCss)
5656
import Text.Pandoc.ImageSize
5757
import Text.Pandoc.Options
58+
import Text.Pandoc.SelfContained (makeSelfContained)
5859
import Text.Pandoc.Shared
5960
import Text.Pandoc.Slides
6061
import Text.Pandoc.Templates (renderTemplate)
@@ -230,9 +231,12 @@ writeHtmlString' st opts d = do
230231
let colwidth = case writerWrapText opts of
231232
WrapAuto -> Just (writerColumns opts)
232233
_ -> Nothing
233-
(if writerPreferAscii opts
234-
then toEntities
235-
else id) <$>
234+
(if writerEmbedResources opts
235+
then makeSelfContained
236+
else pure) =<<
237+
(if writerPreferAscii opts
238+
then toEntities
239+
else id) <$>
236240
case writerTemplate opts of
237241
Nothing -> return $
238242
case colwidth of

0 commit comments

Comments
 (0)