Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move resource embedding into HTML writer [API change] #9982

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/lua-filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions pandoc-lua-engine/test/lua/module/globals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
6 changes: 1 addition & 5 deletions src/Text/Pandoc/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions src/Text/Pandoc/App/OutputSettings.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Text/Pandoc/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -365,6 +366,7 @@ instance Default WriterOptions where
, writerSyntaxMap = defaultSyntaxMap
, writerPreferAscii = False
, writerLinkImages = False
, writerEmbedResources = False
}

instance HasSyntaxExtensions WriterOptions where
Expand Down
10 changes: 7 additions & 3 deletions src/Text/Pandoc/Writers/HTML.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down