File tree Expand file tree Collapse file tree 5 files changed +36
-13
lines changed
src/Text/Pandoc/Lua/Marshal Expand file tree Collapse file tree 5 files changed +36
-13
lines changed Original file line number Diff line number Diff line change 2
2
3
3
` pandoc-lua-marshal ` uses [ PVP Versioning] [ ] .
4
4
5
+ ## 0.1.6.1
6
+
7
+ Released 2022-06-10.
8
+
9
+ - Provide better error messages when fuzzy retrieval of Inlines
10
+ or Blocks fails.
11
+
12
+ - Relax upper bound for text, allow text-2.0.
13
+
5
14
## 0.1.6
6
15
7
16
Released 2022-06-03.
Original file line number Diff line number Diff line change @@ -90,20 +90,22 @@ pushBlocks xs = do
90
90
-- bare strings as @Str@ values.
91
91
peekBlockFuzzy :: LuaError e
92
92
=> Peeker e Block
93
- peekBlockFuzzy = choice
94
- [ peekBlock
95
- , \ idx -> Plain <$!> peekInlinesFuzzy idx
96
- ]
93
+ peekBlockFuzzy idx =
94
+ peekBlock idx
95
+ <|> (Plain <$!> peekInlinesFuzzy idx)
96
+ <|> (failPeek =<<
97
+ typeMismatchMessage " Block or list of Inlines" idx)
97
98
{-# INLINABLE peekBlockFuzzy #-}
98
99
99
100
-- | Try extra-hard to return the value at the given index as a list of
100
101
-- inlines.
101
102
peekBlocksFuzzy :: LuaError e
102
103
=> Peeker e [Block ]
103
- peekBlocksFuzzy = choice
104
- [ peekList peekBlockFuzzy
105
- , (<$!>) pure . peekBlockFuzzy
106
- ]
104
+ peekBlocksFuzzy idx =
105
+ peekList peekBlockFuzzy idx
106
+ <|> (pure <$!> peekBlockFuzzy idx)
107
+ <|> (failPeek =<<
108
+ typeMismatchMessage " Block, list of Blocks, or compatible element" idx)
107
109
{-# INLINABLE peekBlocksFuzzy #-}
108
110
109
111
-- | Block object type.
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ module Text.Pandoc.Lua.Marshal.Inline
25
25
, walkInlinesStraight
26
26
) where
27
27
28
- import Control.Applicative (optional )
28
+ import Control.Applicative ((<|>) , optional )
29
29
import Control.Monad.Catch (throwM )
30
30
import Control.Monad ((<$!>) )
31
31
import Data.Data (showConstr , toConstr )
@@ -93,10 +93,10 @@ peekInlinesFuzzy :: LuaError e
93
93
=> Peeker e [Inline ]
94
94
peekInlinesFuzzy idx = liftLua (ltype idx) >>= \ case
95
95
TypeString -> B. toList . B. text <$> peekText idx
96
- _ -> choice
97
- [ peekList peekInlineFuzzy
98
- , fmap pure . peekInlineFuzzy
99
- ] idx
96
+ _ -> peekList peekInlineFuzzy idx
97
+ <|> ( pure <$> peekInlineFuzzy idx)
98
+ <|> (failPeek =<<
99
+ typeMismatchMessage " Inline, list of Inlines, or string " idx)
100
100
{-# INLINABLE peekInlinesFuzzy #-}
101
101
102
102
-- | Inline object type.
Original file line number Diff line number Diff line change @@ -349,6 +349,12 @@ return {
349
349
{' Header' , ' CodeBlock' }
350
350
)
351
351
end ),
352
+ test (' gives sensible error message' , function ()
353
+ assert .error_matches (
354
+ function () Blocks (nil ) end ,
355
+ ' Block, list of Blocks, or compatible element expected'
356
+ )
357
+ end )
352
358
},
353
359
group ' walk' {
354
360
test (' modifies Inline subelements' , function ()
Original file line number Diff line number Diff line change @@ -318,6 +318,12 @@ return {
318
318
{' Str' , ' Space' , ' Str' }
319
319
)
320
320
end ),
321
+ test (' gives sensible error message' , function ()
322
+ assert .error_matches (
323
+ function () Inlines (nil ) end ,
324
+ " Inline, list of Inlines, or string"
325
+ )
326
+ end )
321
327
},
322
328
group ' walk' {
323
329
test (' modifies Inline subelements' , function ()
You can’t perform that action at this time.
0 commit comments