diff --git a/README.md b/README.md index b6893cd..537bbd2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@
-# office.yazi +# office.yazi (gk fix) ### A plugin to preview office documents in Yazi a duck preview test diff --git a/main.lua b/init.lua similarity index 85% rename from main.lua rename to init.lua index 2390a6c..b8ee4d0 100644 --- a/main.lua +++ b/init.lua @@ -29,30 +29,40 @@ end function M:doc2pdf(job) local tmp = "/tmp/yazi-" .. ya.uid() .. "/" .. ya.hash("office.yazi") .. "/" ---[[ For Future Reference: Regarding `libreoffice` as preconverter + --[[ For Future Reference: Regarding `libreoffice` as preconverter 1. It prints errors to stdout (always, doesn't matter if it succeeded or it failed) 2. Always writes the converted files to the filesystem (so no Mario|Bros|Piping|Magic|To>stdout) --]] + local libreoffice = Command("libreoffice") :args({ "--headless", "--convert-to", - "pdf:draw_pdf_Export:{" .. - "\"PageRange\":{" .. - "\"type\":\"string\"," .. - "\"value\":" .. "\"" .. job.skip + 1 .. "\"" .. - "}" .. - "}", + "pdf:draw_pdf_Export", + "--convert-to", + "pdf:draw_pdf_Export:{" + .. '"PageRange":{' + .. '"type":"string",' + .. '"value":' + .. '"' + .. job.skip + 1 + .. '"' + .. "}" + .. "}", "--outdir", tmp, - tostring(job.file.url) + tostring(job.file.url), }) :stdin(Command.NULL) :stdout(Command.PIPED) :stderr(Command.NULL) :output() - + if not libreoffice.status.success then - ya.err(libreoffice.stdout:match("LibreOffice .+"):gsub("%\n.*", "") .. " " .. libreoffice.stdout:match("Error .+"):gsub("%\n.*", "")) + ya.err( + libreoffice.stdout:match("LibreOffice .+"):gsub("%\n.*", "") + .. " " + .. libreoffice.stdout:match("Error .+"):gsub("%\n.*", "") + ) return nil, Err("Failed to preconvert `%s` to a temporary PDF", job.file.name) end