Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Always wrap tables in captioned-table and let the latter handle … #134

Merged
merged 1 commit into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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