pandoc-lua-marshal 0.1.6.1 → 0.1.7
raw patch · 7 files changed
+63/−9 lines, 7 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Text.Pandoc.Lua.Marshal.TableParts: peekCaptionFuzzy :: LuaError e => Peeker e Caption
Files
- CHANGELOG.md +11/−1
- pandoc-lua-marshal.cabal +2/−2
- src/Text/Pandoc/Lua/Marshal/Block.hs +3/−3
- src/Text/Pandoc/Lua/Marshal/Pandoc.hs +5/−0
- src/Text/Pandoc/Lua/Marshal/TableParts.hs +10/−2
- test/test-block.lua +17/−1
- test/test-pandoc.lua +15/−0
CHANGELOG.md view
@@ -2,6 +2,16 @@ `pandoc-lua-marshal` uses [PVP Versioning][]. +## 0.1.7++Released 2022-07-16.++- Allow Blocks to be passed as Caption value. The resulting+ caption has the Blocks as its long version and no short+ version.++- Add `clone` method to Pandoc elements.+ ## 0.1.6.1 Released 2022-06-10.@@ -37,7 +47,7 @@ functions `filter`, `map`, and `find_if`. These previously required the argument to be of type `function`, which was too restrictive.- + - Inline: the type of Image captions is now `Inlines` instead of `List`.
pandoc-lua-marshal.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.4 name: pandoc-lua-marshal-version: 0.1.6.1+version: 0.1.7 synopsis: Use pandoc types in Lua description: This package provides functions to marshal and unmarshal pandoc document types to and from Lua.@@ -28,7 +28,7 @@ GHC == 8.8.4 GHC == 8.10.7 GHC == 9.0.2- GHC == 9.2.2+ GHC == 9.2.3 extra-source-files: test/test-attr.lua , test/test-block.lua , test/test-cell.lua
src/Text/Pandoc/Lua/Marshal/Block.hs view
@@ -45,7 +45,7 @@ ( peekListAttributes, pushListAttributes ) import Text.Pandoc.Lua.Marshal.Shared (walkBlocksAndInlines) import Text.Pandoc.Lua.Marshal.TableParts- ( peekCaption, pushCaption+ ( peekCaptionFuzzy, pushCaption , peekColSpec, pushColSpec , peekTableBody, pushTableBody , peekTableFoot, pushTableFoot@@ -143,7 +143,7 @@ _ -> const Absent) , possibleProperty "caption" "element caption" (pushCaption, \case {Table _ capt _ _ _ _ -> Actual capt; _ -> Absent})- (peekCaption, \case+ (peekCaptionFuzzy, \case Table attr _ cs h bs f -> Actual . (\c -> Table attr c cs h bs f) _ -> const Absent) , possibleProperty "colspecs" "column alignments and widths"@@ -375,7 +375,7 @@ let attr = fromMaybe nullAttr mattr in return $! attr `seq` capt `seq` colspecs `seq` thead `seq` tbodies `seq` tfoot `seq` Table attr capt colspecs thead tbodies tfoot)- <#> parameter peekCaption "Caption" "caption" "table caption"+ <#> parameter peekCaptionFuzzy "Caption" "caption" "table caption" <#> parameter (peekList peekColSpec) "{ColSpec,...}" "colspecs" "column alignments and widths" <#> parameter peekTableHead "TableHead" "head" "table head"
src/Text/Pandoc/Lua/Marshal/Pandoc.hs view
@@ -63,6 +63,11 @@ (pushMeta, \(Pandoc meta _) -> meta) (peekMeta, \(Pandoc _ blks) meta -> Pandoc meta blks) + , method $ defun "clone"+ ### return+ <#> parameter peekPandoc "Pandoc" "doc" "self"+ =#> functionResult pushPandoc "Pandoc" "cloned Pandoc document"+ , method $ defun "walk" ### flip applyFully <#> parameter peekPandoc "Pandoc" "self" ""
src/Text/Pandoc/Lua/Marshal/TableParts.hs view
@@ -10,6 +10,7 @@ -} module Text.Pandoc.Lua.Marshal.TableParts ( peekCaption+ , peekCaptionFuzzy , pushCaption , peekColSpec , pushColSpec@@ -28,7 +29,7 @@ , mkTableHead ) where -import Control.Applicative (optional)+import Control.Applicative ((<|>), optional) import Control.Monad ((<$!>)) import HsLua import Text.Pandoc.Lua.Marshal.Alignment (peekAlignment, pushAlignment)@@ -52,10 +53,17 @@ -- | Peek Caption element peekCaption :: LuaError e => Peeker e Caption-peekCaption = retrieving "Caption" . \idx -> do+peekCaption idx = do short <- optional $ peekFieldRaw peekInlinesFuzzy "short" idx long <- peekFieldRaw peekBlocksFuzzy "long" idx return $! Caption short long++peekCaptionFuzzy :: LuaError e => Peeker e Caption+peekCaptionFuzzy = retrieving "Caption" . \idx -> do+ peekCaption idx+ <|> (Caption Nothing <$!> peekBlocksFuzzy idx)+ <|> (failPeek =<<+ typeMismatchMessage "Caption, list of Blocks, or compatible element" idx) -- | Push a ColSpec value as a pair of Alignment and ColWidth. pushColSpec :: LuaError e => Pusher e ColSpec
test/test-block.lua view
@@ -319,7 +319,23 @@ Table({long = {}}, {}, TableHead(), {}, new_foot), tbl )- end)+ end),+ test('caption field accepts list of blocks', function ()+ local caption = {long = {Plain 'cap'}}+ local tbl = Table(caption, {}, TableHead(), {}, TableFoot())+ assert.are_same(tbl.caption, {long = {Plain 'cap'}})++ tbl.caption = {Plain 'extended'}++ local new_caption = {+ short = nil,+ long = {Plain 'extended'}+ }+ assert.are_equal(+ Table(new_caption, {}, TableHead(), {}, TableFoot()),+ tbl+ )+ end), }, }, group "Blocks" {
test/test-pandoc.lua view
@@ -45,6 +45,21 @@ ) end) },+ group 'clone' {+ test('cloned value is equal to original', function ()+ local doc = Pandoc({'test'}, {foo = 'hi'})+ assert.are_same(doc, doc:clone())+ end),+ test('changing the clone does not affect original', function ()+ local orig = Pandoc({'test'}, {foo = 'hi'})+ local copy = orig:clone()++ copy.blocks[1] = Plain 'different'+ assert.are_same(orig.meta, copy.meta)+ assert.are_same(Blocks{'test'}, orig.blocks)+ assert.are_same(Blocks{'different'}, copy.blocks)+ end),+ }, group 'walk' { test('uses `Meta` function', function () local meta = {