diff options
| author | Albert Krewinkel <[email protected]> | 2025-05-28 11:10:51 +0200 |
|---|---|---|
| committer | Albert Krewinkel <[email protected]> | 2025-05-28 13:19:01 +0200 |
| commit | ce5e2a2efc0823833040f917d4470da82b634c13 (patch) | |
| tree | 060834c00de6412a0ea69b8fdc3f89939aec520d /pandoc-lua-engine/src | |
| parent | ccc0a5a630df414a580c5c58f1b0ad8133e1a398 (diff) | |
Lua: add function `pandoc.mediabag.make_data_uri`.
The function takes a MIME type and raw data from which it creates an
RFC 2397 data URI.
Closes: #10876
Diffstat (limited to 'pandoc-lua-engine/src')
| -rw-r--r-- | pandoc-lua-engine/src/Text/Pandoc/Lua/Module/MediaBag.hs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/MediaBag.hs b/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/MediaBag.hs index 44957e246..da666779a 100644 --- a/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/MediaBag.hs +++ b/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/MediaBag.hs @@ -27,6 +27,7 @@ import Text.Pandoc.Lua.Marshal.List (pushPandocList) import Text.Pandoc.Lua.Orphans () import Text.Pandoc.Lua.PandocLua (unPandocLua) import Text.Pandoc.MIME (MimeType) +import Text.Pandoc.SelfContained (makeDataURI) import qualified Data.ByteString.Lazy as BL import qualified Data.Text as T @@ -60,6 +61,7 @@ documentedModule = Module , items `since` makeVersion [2,7,3] , list `since` makeVersion [2,0] , lookup `since` makeVersion [2,0] + , make_data_uri `since` makeVersion [3,7,1] , write `since` makeVersion [3,0] ] , moduleOperations = [] @@ -243,6 +245,29 @@ fetch = defun "fetch" , " local mt, contents = pandoc.mediabag.fetch(diagram_url)" ] +make_data_uri :: DocumentedFunction PandocError +make_data_uri = defun "make_data_uri" + ### (\mime raw -> pure $ makeDataURI (mime, raw)) + <#> parameter Lua.peekText "string" "mime_type" "MIME type of the data" + <#> parameter Lua.peekByteString "string" "raw_data" "data to encode" + =#> functionResult Lua.pushText "string" "data uri" + #? T.unlines + [ "Convert the input data into a data URI as defined by RFC 2397." + , "" + , "Example:" + , "" + , " -- Embed an unofficial pandoc logo" + , " local pandoc_logo_url = 'https://raw.githubusercontent.com/'" + , " .. 'tarleb/pandoc-logo/main/pandoc.svg'" + , "" + , " local datauri = pandoc.mediabag.make_data_uri(" + , " pandoc.mediabag.fetch(pandoc_logo_url)" + , " )" + , "" + , " local image = pandoc.Image('Logo', datauri)" + ] + + -- | Extract the mediabag or just a single entry. write :: DocumentedFunction PandocError write = defun "write" |
