aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Text/Pandoc/Lua/Marshaling/AST.hs11
-rw-r--r--test/lua/module/pandoc.lua28
2 files changed, 33 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Lua/Marshaling/AST.hs b/src/Text/Pandoc/Lua/Marshaling/AST.hs
index 568b610cc..31d040c83 100644
--- a/src/Text/Pandoc/Lua/Marshaling/AST.hs
+++ b/src/Text/Pandoc/Lua/Marshaling/AST.hs
@@ -67,6 +67,7 @@ import Text.Pandoc.Lua.Marshaling.ListAttributes
(peekListAttributes, pushListAttributes)
import qualified HsLua as Lua
+import qualified Text.Pandoc.Builder as B
import qualified Text.Pandoc.Lua.Util as LuaUtil
instance Pushable Pandoc where
@@ -796,10 +797,12 @@ peekInlineFuzzy = retrieving "Inline" . choice
-- | Try extra-hard to return the value at the given index as a list of
-- inlines.
peekInlinesFuzzy :: LuaError e => Peeker e [Inline]
-peekInlinesFuzzy = choice
- [ peekList peekInlineFuzzy
- , fmap pure . peekInlineFuzzy
- ]
+peekInlinesFuzzy idx = liftLua (ltype idx) >>= \case
+ TypeString -> B.toList . B.text <$> peekText idx
+ _ -> choice
+ [ peekList peekInlineFuzzy
+ , fmap pure . peekInlineFuzzy
+ ] idx
-- | Try extra hard to retrieve a Block value from the stack. Treats bar
-- Inline elements as if they were wrapped in 'Plain'.
diff --git a/test/lua/module/pandoc.lua b/test/lua/module/pandoc.lua
index 4f4a9b27e..b191bcb3c 100644
--- a/test/lua/module/pandoc.lua
+++ b/test/lua/module/pandoc.lua
@@ -480,7 +480,10 @@ return {
assert.are_same(deflist.content[1][2][2],
{pandoc.Plain{pandoc.Str 'company'}})
assert.are_same(deflist.content[2][2],
- {{pandoc.Plain{pandoc.Str 'Best when hot.'}}})
+ {{pandoc.Plain{
+ pandoc.Str 'Best', pandoc.Space(),
+ pandoc.Str 'when', pandoc.Space(),
+ pandoc.Str 'hot.'}}})
end),
test('modify items via property `content`', function ()
local deflist = pandoc.DefinitionList{
@@ -532,7 +535,7 @@ return {
assert.are_same(header.content, {pandoc.Str 'test'})
header.content = {'new text'}
- assert.are_equal(header, pandoc.Header(1, 'new text'))
+ assert.are_equal(header, pandoc.Header(1, {'new text'}))
end),
test('access Attr via property `attr`', function ()
local header = pandoc.Header(1, 'test', {'my-test'})
@@ -968,5 +971,26 @@ return {
)
assert.are_equal('1234', table.concat(acc))
end)
+ },
+
+ group 'Marshal' {
+ group 'Inlines' {
+ test('Strings are broken into words', function ()
+ assert.are_equal(
+ pandoc.Emph 'Nice, init?',
+ pandoc.Emph{pandoc.Str 'Nice,', pandoc.Space(), pandoc.Str 'init?'}
+ )
+ end)
+ },
+ group 'Blocks' {
+ test('Strings are broken into words and wrapped in Plain', function ()
+ assert.are_equal(
+ pandoc.Div{
+ pandoc.Plain{pandoc.Str 'Nice,', pandoc.Space(), pandoc.Str 'init?'}
+ },
+ pandoc.Div{'Nice, init?'}
+ )
+ end)
+ }
}
}