Skip to content
Open
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
12 changes: 11 additions & 1 deletion lua/render-markdown/handler/latex.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,14 @@ function Handler.convert(cmd, inputs)
if vim.system then
local tasks = {} ---@type table<string, vim.SystemObj>
for _, input in ipairs(inputs) do
tasks[input] = vim.system({ cmd }, { stdin = input, text = true })
tasks[input] = vim.system({ cmd }, {
stdin = input,
text = true,
-- Python defaults redirected streams to the active code page on
-- Windows. latex2text can emit characters that code page cannot
-- represent, causing the converter to exit with an encoding error.
env = { PYTHONIOENCODING = 'utf-8' },
})
end
for input, task in pairs(tasks) do
local output = task:wait()
Expand All @@ -113,6 +120,8 @@ function Handler.convert(cmd, inputs)
end
end
else
local encoding = vim.env.PYTHONIOENCODING
vim.env.PYTHONIOENCODING = 'utf-8'
for _, input in ipairs(inputs) do
local result = vim.fn.system(cmd, input)
if vim.v.shell_error == 0 and result then
Expand All @@ -121,6 +130,7 @@ function Handler.convert(cmd, inputs)
failed[#failed + 1] = input
end
end
vim.env.PYTHONIOENCODING = encoding
end
return failed
end
Expand Down
1 change: 1 addition & 0 deletions tests/helpers/system.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function M.mock(command, outputs)
end)
stub.new(vim, 'system', function(cmd, opts)
assert.same({ command }, cmd)
assert.same({ PYTHONIOENCODING = 'utf-8' }, opts.env)
local output = outputs[opts.stdin]
assert.not_nil(output, ('missing output: %s'):format(opts.stdin))
return Task.new(table.concat(output, '\n') .. '\n')
Expand Down