-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathpandoc.lua
More file actions
44 lines (42 loc) · 1.39 KB
/
pandoc.lua
File metadata and controls
44 lines (42 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
local utils = require("kide.core.utils")
local M = {}
local cjk_mainfont = function()
if utils.is_win then
return "Microsoft YaHei UI"
elseif utils.is_linux then
return "Noto Sans CJK SC"
else
return "Yuanti SC"
end
end
-- pandoc --pdf-engine=xelatex --highlight-style tango -N --toc -V CJKmainfont="Yuanti SC" -V mainfont="Hack" -V geometry:"top=2cm, bottom=1.5cm, left=2cm, right=2cm" test.md -o out.pdf
M.markdown_to_pdf = function()
local group = vim.api.nvim_create_augroup("kide_utils_pandoc", { clear = true })
vim.api.nvim_create_autocmd({ "FileType" }, {
group = group,
pattern = { "markdown" },
desc = "Markdown to PDF",
callback = function(o)
vim.api.nvim_buf_create_user_command(o.buf, "PandocMdToPdf", function(_)
require("pandoc.render").file({
{ "--pdf-engine", "xelatex" },
{ "--highlight-style", "tango" },
{ "--number-sections" },
{ "--toc" },
{ "--variable", "CJKmainfont=" .. cjk_mainfont() },
{ "--variable", "mainfont=Hack" },
{ "--variable", "sansfont=Hack" },
{ "--variable", "monofont=Hack" },
{ "--variable", "geometry:top=2cm, bottom=1.5cm, left=2cm, right=2cm" },
})
end, {
nargs = "*",
complete = require("pandoc.utils").complete,
})
end,
})
end
M.setup = function()
M.markdown_to_pdf()
end
return M