Skip to content

Commit

Permalink
add pandoc integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Junker committed Jul 11, 2022
1 parent 3cd393b commit e55fa51
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ require("nuke").setup{
| Markdown | | glow/lowdown/mdless | |
| HTML | | w3m/elinks/lynx | |
| MS doc | | antiword/catdoc/wvWare | |
| MS docx | | libreoffice | |
| MS docx | | pandoc/libreoffice | |
| MS xls | | xlhtml/xls2csv | |
| MS xlsx | | libreoffice | |
| Epub | | | einfo |
| Epub | | pandoc | einfo |

*recomended terminal emulator with support of [Terminal graphics protocol](https://sw.kovidgoyal.net/kitty/graphics-protocol/)*

Expand Down
26 changes: 24 additions & 2 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,9 @@ local function smart_view_doc(node)
end

local function smart_view_docx(node)
if program_exists("lowriter") then
if program_exists("pandoc") then
return exec_paging("pandoc", node, "-o -", "-t plain")
elseif program_exists("lowriter") then
return {{ BashExec = 'VIEWRTMP=`mktemp -q -d ${TMPDIR:-/tmp}/xplr-nuke.XXXXXX` && cp "'
.. node.absolute_path
.. '" $VIEWRTMP/temp.docx && cd $VIEWRTMP && libreoffice --headless --convert-to txt $VIEWRTMP/temp.docx > /dev/null 2>&1 && cat $VIEWRTMP/temp.txt | '
Expand Down Expand Up @@ -480,6 +482,22 @@ local function smart_view_xls(node)
end
end

local function smart_view_epub(node)
if program_exists("pandoc") then
return exec_paging("pandoc", node, "-o -", "-t plain")
end

return info_view_epub(node)
end

local function smart_view_fb2(node)
if program_exists("pandoc") then
return exec_paging("pandoc", node, "-o -", "-t plain")
end

return info_view_epub(node)
end

local function smart_view(ctx)
local node = ctx.focused_node
local node_mime = node.mime_essence
Expand Down Expand Up @@ -514,12 +532,16 @@ local function smart_view(ctx)
["application/vnd.openxmlformats-officedocument.wordprocessingml.document"] = function() return smart_view_docx(node) end,
["application/vnd.ms-excel"] = function() return smart_view_xls(node) end,
["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"] = function() return smart_view_xlsx(node) end,
["application/epub+zip"] = function() return info_view_epub(node) end,
["application/epub+zip"] = function() return smart_view_epub(node) end,
}

local res = _case(node_mime, cases);
if res then return res end

local cases = {
["fb2"] = function() return smart_view_fb2(node) end,
}

if node_mime:match("^image/.*") then
return smart_view_image(node)
elseif node_mime:match("^video/.*") then
Expand Down

0 comments on commit e55fa51

Please sign in to comment.