|
|
@@ -0,0 +1,29 @@
|
|
|
+return {
|
|
|
+ pandoc_format_docstring = function()
|
|
|
+ local api, fn, bo = vim.api, vim.fn, vim.bo
|
|
|
+
|
|
|
+ local start_lnum = fn.search('"""', "bnc")
|
|
|
+ local end_lnum = fn.search('"""', "nc")
|
|
|
+ if start_lnum == 0 or end_lnum == 0 then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ local content = table.concat(
|
|
|
+ api.nvim_buf_get_lines(0, start_lnum - 1, end_lnum, false), "\n")
|
|
|
+ :gsub('^%s*"""', ""):gsub('"""%s*$', "")
|
|
|
+
|
|
|
+ local cols = (bo.textwidth > 0) and bo.textwidth or 80
|
|
|
+ local cmd = string.format(
|
|
|
+ "pandoc --from=commonmark --to=commonmark --wrap=auto --columns=%d",
|
|
|
+ cols)
|
|
|
+ local result = fn.system(cmd, content)
|
|
|
+
|
|
|
+ if vim.v.shell_error ~= 0 then
|
|
|
+ return print("Pandoc Error: " .. result)
|
|
|
+ end
|
|
|
+
|
|
|
+ local new_lines = vim.split('"""' .. fn.trim(result) .. '"""', "\n",
|
|
|
+ { trimempty = false })
|
|
|
+ api.nvim_buf_set_lines(0, start_lnum - 1, end_lnum, false, new_lines)
|
|
|
+ end
|
|
|
+}
|