papaja icon indicating copy to clipboard operation
papaja copied to clipboard

[bug report] Bug of rendering docx with pandoc-crossref by docx_fixed.lua

Open panwanke opened this issue 4 months ago • 2 comments

When I tried to render rmd as docx using the latest version of pandoc and pandoc-crossref, I encountered the following bugs:

Error running filter .../papaja/lua/docx_fixes.lua:
.../papaja/lua/docx_fixes.lua:24: attempt to index a nil value (field 'integer index')
stack traceback:
error: pandoc document conversion failed with error 83

I tried to fix this bug by modifying lua, mainly to recognize that the Table function is skipped when adding pandoc-crossref causes the tbl.caption.long to be empty.

function Table(tbl)
  -- Check if tbl.caption.long is not empty
  if #tbl.caption.long > 0 then
    local caption = tbl.caption.long[1].content

    -- Modify the caption if it's not nil
    if caption[1] ~= nil then
      -- Your existing code to modify the caption
      caption[3] = pandoc.Str(string.gsub(pandoc.utils.stringify(caption[3]), ":", ""))
      caption[4] = pandoc.LineBreak()
      -- ... (rest of the caption modification code)
    end

    -- Assign the modified caption back to the table
    tbl.caption.long[1].content = caption
  end

  -- Return the modified table
  return tbl
end

After testing, this method is feasible.

panwanke avatar Feb 09 '24 11:02 panwanke