Skip to content

Commit

Permalink
Merge pull request #134 from Omikhleia/always-wrap-tables
Browse files Browse the repository at this point in the history
fix: Always wrap tables in captioned-table and let the latter handle …
  • Loading branch information
Omikhleia authored Dec 14, 2024
2 parents 2b977f9 + a521387 commit 73c2733
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 21 deletions.
9 changes: 3 additions & 6 deletions inputters/djot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,11 @@ function Renderer:table (node)
header = SU.boolean(row.head, false),
}, self:render_children(node), pos)

if not caption then
return ptable
end
local captioned = {
local wrapped = caption and {
ptable,
createCommand("caption", {}, caption, pos)
}
return createStructuredCommand("markdown:internal:captioned-table", options, captioned, pos)
} or { ptable }
return createStructuredCommand("markdown:internal:captioned-table", options, wrapped, pos)
end

function Renderer:row (node)
Expand Down
10 changes: 3 additions & 7 deletions inputters/markdown.lua
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,11 @@ local function SileAstWriter (writerOps, renderOps)
end
local ptable = createStructuredCommand("ptable", { header = true, cols = table.concat(cWidth, " ") }, ptableRows)

if not caption then
return ptable
end

local captioned = {
local wrapped = caption and {
ptable,
createCommand("caption", {}, caption)
}
return createStructuredCommand("markdown:internal:captioned-table", {}, captioned)
} or { ptable }
return createStructuredCommand("markdown:internal:captioned-table", {}, wrapped)
end

writer.definitionlist = function (items, _) -- items, tight
Expand Down
12 changes: 5 additions & 7 deletions inputters/pandocast.lua
Original file line number Diff line number Diff line change
Expand Up @@ -408,15 +408,13 @@ function Renderer:Table (_, caption, colspecs, thead, tbodies, tfoot)
}, ptableRows)

-- Caption (Maybe ShortCaption) [Block]
if not caption or #caption[#caption] == 0 then
-- No block or empty block = no caption...
return ptable
end
local captioned = {
-- No block or empty block = no caption..
local hasCaption = caption and #caption[#caption] > 0
local wrapped = hasCaption and {
ptable,
createCommand("caption", {}, self:render(caption[#caption]))
}
return createStructuredCommand("markdown:internal:captioned-table", {}, captioned)
} or { ptable }
return createStructuredCommand("markdown:internal:captioned-table", {}, wrapped)
end

-- Figure Attr Caption [Block]
Expand Down
2 changes: 1 addition & 1 deletion packages/markdown/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -898,8 +898,8 @@ Please consider using a resilient-compatible class!]])
}, function ()
SILE.call("center", {}, caption)
end)
SILE.call("smallskip")
end
SILE.call("smallskip")
end, "A fallback command for Markdown to insert a captioned table")

self:registerCommand("markdown:fallback:defn", function (_, content)
Expand Down

0 comments on commit 73c2733

Please sign in to comment.