diff --git a/doc/lua-filters.md b/doc/lua-filters.md index 9de10cfbf9cc..ddfa795292a3 100644 --- a/doc/lua-filters.md +++ b/doc/lua-filters.md @@ -2132,6 +2132,9 @@ Fields: : How to obfuscate emails -- one of 'none', 'references', or 'javascript' (string) +`embed_resources` +: Whether resources should be embedded in HTML output (boolean) + `epub_chapter_level` : Header level for chapters, i.e., how the document is split into separate files (integer) diff --git a/pandoc-lua-engine/src/Text/Pandoc/Lua/Marshal/WriterOptions.hs b/pandoc-lua-engine/src/Text/Pandoc/Lua/Marshal/WriterOptions.hs index ad03b7d51445..c0e012f93991 100644 --- a/pandoc-lua-engine/src/Text/Pandoc/Lua/Marshal/WriterOptions.hs +++ b/pandoc-lua-engine/src/Text/Pandoc/Lua/Marshal/WriterOptions.hs @@ -80,6 +80,11 @@ typeWriterOptions = deftype "WriterOptions" (pushViaJSON, writerEmailObfuscation) (peekViaJSON, \opts x -> opts{ writerEmailObfuscation = x }) + , property "embed_resources" + "Whether resources should be embedded in HTML output" + (pushViaJSON, writerEmbedResources) + (peekViaJSON, \opts x -> opts{ writerEmbedResources = x }) + , property "split_level" "Level at which EPUB or chunked HTML documents are split into files" (pushIntegral, writerSplitLevel) diff --git a/pandoc-lua-engine/test/lua/module/globals.lua b/pandoc-lua-engine/test/lua/module/globals.lua index 4df133e46602..e183f68f365c 100644 --- a/pandoc-lua-engine/test/lua/module/globals.lua +++ b/pandoc-lua-engine/test/lua/module/globals.lua @@ -23,6 +23,9 @@ return { test('email_obfuscation', function () assert.are_equal(type(PANDOC_WRITER_OPTIONS.email_obfuscation), 'string') end), + test('embed_resources', function () + assert.are_equal(type(PANDOC_WRITER_OPTIONS.embed_resources), 'boolean') + end), test('split_level', function () assert.are_equal(type(PANDOC_WRITER_OPTIONS.split_level), 'number') end), diff --git a/src/Text/Pandoc/App.hs b/src/Text/Pandoc/App.hs index 4ae62f401d49..d1f63f279ec3 100644 --- a/src/Text/Pandoc/App.hs +++ b/src/Text/Pandoc/App.hs @@ -65,7 +65,6 @@ import Text.Pandoc.Filter (Filter (JSONFilter, LuaFilter), Environment (..), import qualified Text.Pandoc.Format as Format import Text.Pandoc.PDF (makePDF) import Text.Pandoc.Scripting (ScriptingEngine (..), CustomComponents(..)) -import Text.Pandoc.SelfContained (makeSelfContained) import Text.Pandoc.Shared (tshow) import Text.Pandoc.URI (isURI) import Text.Pandoc.Writers.Shared (lookupMetaString) @@ -329,10 +328,7 @@ convertWithOpts' scriptingEngine istty datadir opts = do | standalone = t | T.null t || T.last t /= '\n' = t <> T.singleton '\n' | otherwise = t - textOutput <- ensureNl <$> f writerOptions doc - if (optSelfContained opts || optEmbedResources opts) && htmlFormat format - then TextOutput <$> makeSelfContained textOutput - else return $ TextOutput textOutput + TextOutput . ensureNl <$> f writerOptions doc reports <- getLog return (output, reports) diff --git a/src/Text/Pandoc/App/OutputSettings.hs b/src/Text/Pandoc/App/OutputSettings.hs index 11d813e5e6bb..da7ecf31430b 100644 --- a/src/Text/Pandoc/App/OutputSettings.hs +++ b/src/Text/Pandoc/App/OutputSettings.hs @@ -263,6 +263,8 @@ optToOutputSettings scriptingEngine opts = do , writerSyntaxMap = syntaxMap , writerPreferAscii = optAscii opts , writerLinkImages = optLinkImages opts + , writerEmbedResources = optEmbedResources opts || + optSelfContained opts } return $ OutputSettings { outputFormat = format diff --git a/src/Text/Pandoc/Options.hs b/src/Text/Pandoc/Options.hs index e4ff56b7741a..88a986ab5538 100644 --- a/src/Text/Pandoc/Options.hs +++ b/src/Text/Pandoc/Options.hs @@ -326,6 +326,7 @@ data WriterOptions = WriterOptions , writerSyntaxMap :: SyntaxMap , writerPreferAscii :: Bool -- ^ Prefer ASCII representations of characters when possible , writerLinkImages :: Bool -- ^ Use links rather than embedding ODT images + , writerEmbedResources :: Bool -- ^ Embed resources in HTML } deriving (Show, Data, Typeable, Generic) instance Default WriterOptions where @@ -365,6 +366,7 @@ instance Default WriterOptions where , writerSyntaxMap = defaultSyntaxMap , writerPreferAscii = False , writerLinkImages = False + , writerEmbedResources = False } instance HasSyntaxExtensions WriterOptions where diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs index c03ffaac2769..de2e79af59bb 100644 --- a/src/Text/Pandoc/Writers/HTML.hs +++ b/src/Text/Pandoc/Writers/HTML.hs @@ -55,6 +55,7 @@ import Text.Pandoc.Highlighting (formatHtmlBlock, formatHtml4Block, formatHtmlInline, highlight, styleToCss) import Text.Pandoc.ImageSize import Text.Pandoc.Options +import Text.Pandoc.SelfContained (makeSelfContained) import Text.Pandoc.Shared import Text.Pandoc.Slides import Text.Pandoc.Templates (renderTemplate) @@ -230,9 +231,12 @@ writeHtmlString' st opts d = do let colwidth = case writerWrapText opts of WrapAuto -> Just (writerColumns opts) _ -> Nothing - (if writerPreferAscii opts - then toEntities - else id) <$> + (if writerEmbedResources opts + then makeSelfContained + else pure) =<< + (if writerPreferAscii opts + then toEntities + else id) <$> case writerTemplate opts of Nothing -> return $ case colwidth of