diff --git a/README.md b/README.md index 753f524..6353cbe 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,9 @@ [![CI](https://github.com/phanen/mder.nvim/actions/workflows/ci.yml/badge.svg)](https://github.com/phanen/mder.nvim/actions/workflows/ci.yml) -# mder.nvim +# mder.nvim ## Install -```lua -{ "phanen/mder.nvim", ft = "markdown", config = true }, -``` +> BREAKING CHANGES: this lib provide api only now -## Config -see `config.lua` ```lua -local default_opts = { - ft = { "markdown", "typst" }, - line = "", - codeblock = "", - listdn = "o", - listup = "O", - img_link = "zi", - raw_link = "zj", -} +{ "phanen/mder.nvim", ft = "markdown" } ``` - -## API -see `commands.lua` diff --git a/lua/mder/codeblock.lua b/lua/mder/codeblock.lua index be7e905..dda7cc4 100644 --- a/lua/mder/codeblock.lua +++ b/lua/mder/codeblock.lua @@ -1,5 +1,7 @@ -- surround codeblock with correct indent -local wrap_codeblock = function() +local M = {} + +M.surround = function() local vs, ve = vim.fn.getpos(".")[2], vim.fn.getpos("v")[2] if vs > ve then vs, ve = ve, vs @@ -15,6 +17,4 @@ local wrap_codeblock = function() vim.api.nvim_feedkeys("A", "n", false) end -return { - wrap_codeblock = wrap_codeblock, -} +return M diff --git a/lua/mder/commands.lua b/lua/mder/commands.lua deleted file mode 100644 index 58003a0..0000000 --- a/lua/mder/commands.lua +++ /dev/null @@ -1,8 +0,0 @@ -return { - codeblock = function() return require("mder.codeblock").wrap_codeblock() end, - line = function() return require("mder.line").toggle_lines() end, - listdn = function() return require("mder.autolist").listdn() end, - listup = function() return require("mder.autolist").listup() end, - img_link = function() return require("mder.link").wrap_or_paste_img() end, - raw_link = function() return require("mder.link").wrap_or_paste_raw() end, -} diff --git a/lua/mder/config.lua b/lua/mder/config.lua deleted file mode 100644 index d40cfe7..0000000 --- a/lua/mder/config.lua +++ /dev/null @@ -1,34 +0,0 @@ -local M = {} - -local default_opts = { - ft = { "markdown", "typst" }, - keymap = { - line = "", - codeblock = "", - listdn = "o", - listup = "O", - img_link = "zi", - raw_link = "zj", - }, -} - -M.check_box = "%[x%]" -M.empty_box = "%[ %]" - -M.setup = function(opts) - opts = vim.tbl_deep_extend("force", default_opts, opts or {}) - vim.api.nvim_create_autocmd("Filetype", { - pattern = opts.ft, - callback = function() - local map = function(mode, act) vim.keymap.set(mode, opts.keymap[act], require("mder")[act], { buffer = 0 }) end - map({ "n", "x" }, "line") - map({ "x" }, "codeblock") - map({ "n" }, "listdn") - map({ "n" }, "listup") - map({ "n", "x" }, "img_link") - map({ "n", "x" }, "raw_link") - end, - }) -end - -return M diff --git a/lua/mder/init.lua b/lua/mder/init.lua deleted file mode 100644 index 32b2ff3..0000000 --- a/lua/mder/init.lua +++ /dev/null @@ -1,7 +0,0 @@ -local M = {} - -M.setup = function(opts) require("mder.config").setup(opts) end - -return setmetatable(M, { - __index = function(_, k) return require("mder.commands")[k] end, -}) diff --git a/lua/mder/utils.lua b/lua/mder/utils.lua index 932632b..848c061 100644 --- a/lua/mder/utils.lua +++ b/lua/mder/utils.lua @@ -1,6 +1,8 @@ +local M = {} + -- 0-index, exclusive, linewise -- also "correct" in normal mode -local visual_region = function() +M.visual_region = function() local vs, ve = vim.fn.line ".", vim.fn.line "v" if vs > ve then vs, ve = ve, vs @@ -8,6 +10,4 @@ local visual_region = function() return vs - 1, ve end -return { - visual_region = visual_region, -} +return M