Skip to content

Commit b15e11a

Browse files
authored
feat(core): implement edit markdown table (#1)
* chore(ci): add release workflow * feat(core): implement core feature * chore(makefile): add * docs(readme): add * docs(vim): add help
1 parent 3780285 commit b15e11a

File tree

7 files changed

+202
-0
lines changed

7 files changed

+202
-0
lines changed

.github/workflows/main.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: main
2+
on:
3+
push:
4+
branches:
5+
- master
6+
- main
7+
pull_request:
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
timeout-minutes: 10
12+
steps:
13+
- name: Release
14+
uses: go-semantic-release/action@v1
15+
if: github.ref == 'refs/heads/main'
16+
with:
17+
github-token: ${{ secrets.GITHUB_TOKEN }}

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# edit-markdown-table.nvim
2+
3+
[![main](https://github.com/kiran94/edit-markdown-table.nvim/actions/workflows/main.yaml/badge.svg)](https://github.com/kiran94/edit-markdown-table.nvim/actions/workflows/main.yaml)
4+
5+
> Edit Markdown Tables from Neovim
6+
7+
`edit-markdown-table.nvim` is a simple plugin which makes updating markdown tables a breeze, even for tables with length strings. See the [preview](#Preview) for a demo.
8+
9+
## Install
10+
11+
Using `lazy.nvim`:
12+
13+
```lua
14+
{
15+
'kiran94/edit-markdown-table.nvim',
16+
config = function()
17+
require('edit-markdown-table').setup()
18+
end,
19+
dependencies = { "nvim-treesitter/nvim-treesitter" },
20+
cmd = "EditMarkdownTable",
21+
},
22+
```
23+
24+
### Dependencies
25+
26+
- Neovim 0.9+
27+
- The [Treesitter](https://github.com/nvim-treesitter/nvim-treesitter#language-parsers) `markdown` parser installed (`:TSInstall markdown`)
28+
29+
### Usage
30+
31+
Place your cursor on the cell of the markdown table that you want to edit.
32+
33+
```lua
34+
:lua require('edit-markdown-table').edit_cell() -- or :EditMarkdownTable
35+
```
36+
37+
## Preview
38+
39+
[![asciicast](https://asciinema.org/a/M2cPbIFc3EpnDctPbRL6Zk3nU.svg)](https://asciinema.org/a/M2cPbIFc3EpnDctPbRL6Zk3nU)
40+
41+
In this example, we are editing this [example](doc/example.md). You can see that especially when `wrap` is turned on, it can be difficult to get a clear view of what you are editing. This plugin simplifies this process by opening a dialog with the text of the current cell so you can make your changes and apply them back to the table.
42+
43+
*This plugin uses `vim.ui.input` for the input dialog. In this preview, I am using [`dressing.nvim`](https://github.com/stevearc/dressing.nvim) to provide the UI with the following configuration:*
44+
45+
```lua
46+
require("dressing").setup({
47+
input = {
48+
enabled = true,
49+
start_in_insert = false,
50+
win_options = {
51+
winblend = 0,
52+
wrap = true,
53+
},
54+
}
55+
})
56+
```

doc/edit-markdown-table.txt

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
edit-markdown-table.txt
2+
3+
================================================================================
4+
CONTENTS *edit-markdown-table-contents*
5+
6+
1. edit-markdown-table.nvim.........|edit-markdown-table-edit-markdown-table.nvim|
7+
1.1. Install.....................................|edit-markdown-table-install|
8+
1.1.1. Dependencies.....................|edit-markdown-table-dependencies|
9+
1.1.2. Usage...................................|edit-markdown-table-usage|
10+
1.2. Preview.....................................|edit-markdown-table-preview|
11+
12+
================================================================================
13+
EDIT-MARKDOWN-TABLE.NVIM *edit-markdown-table-edit-markdown-table.nvim*
14+
15+
[](https://github.com/kiran94/edit-markdown-table.nvim/actions/workflows/main.yaml)
16+
>
17+
Edit Markdown Tables from Neovim
18+
<
19+
20+
`edit-markdown-table.nvim` is a simple plugin which makes updating markdown tables a breeze, even for tables with length strings. See the preview (#Preview) for a demo.
21+
22+
--------------------------------------------------------------------------------
23+
INSTALL *edit-markdown-table-install*
24+
25+
Using `lazy.nvim`:
26+
>
27+
{
28+
'kiran94/edit-markdown-table.nvim',
29+
config = function()
30+
require('edit-markdown-table').setup()
31+
end,
32+
dependencies = { "nvim-treesitter/nvim-treesitter" },
33+
cmd = "EditMarkdownTable",
34+
},
35+
<
36+
37+
DEPENDENCIES *edit-markdown-table-dependencies*
38+
39+
* Neovim 0.9+
40+
* The Treesitter (https://github.com/nvim-treesitter/nvim-treesitter#language-parsers) `markdown` parser installed (`:TSInstall markdown`)
41+
42+
USAGE *edit-markdown-table-usage*
43+
44+
Place your cursor on the cell of the markdown table that you want to edit.
45+
>
46+
:lua require('edit-markdown-table').edit_cell() -- or :EditMarkdownTable
47+
<
48+
49+
--------------------------------------------------------------------------------
50+
PREVIEW *edit-markdown-table-preview*
51+
52+
[](https://asciinema.org/a/M2cPbIFc3EpnDctPbRL6Zk3nU)
53+
54+
In this example, we are editing this example (doc/example.md). You can see that especially when `wrap` is turned on, it can be difficult to get a clear view of what you are editing. This plugin simplifies this process by opening a dialog with the text of the current cell so you can make your changes and apply them back to the table.
55+
56+
This plugin uses `vim.ui.input` for the input dialog. In this preview, I am using `dressing.nvim` (https://github.com/stevearc/dressing.nvim) to provide the UI with the following configuration:
57+
>
58+
require("dressing").setup({
59+
input = {
60+
enabled = true,
61+
start_in_insert = false,
62+
win_options = {
63+
winblend = 0,
64+
wrap = true,
65+
},
66+
}
67+
})
68+
<
69+

doc/example.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# EXAMPLE
2+
3+
| Variable Name | Description |
4+
| --- | --- |
5+
| `PATH` | A colon-separated list of directories in which the shell looks for executable files. When a user types a command into the shell, it searches for the corresponding executable in each directory listed in the `PATH` variable until it finds a match. |
6+
| `HOME` | The current user's home directory. This is the default directory that the shell opens in when a user logs in. It's also used as the base directory for a number of other configuration files and user-specific data. |
7+
| `USER` | The username of the current user. This is used to identify the user when logging in and is also used by some programs to determine file ownership and access permissions. |
8+
| `LANG` | The system's default language setting. This variable specifies the language used for system messages and error messages, as well as the default character set used for text input and output.|
9+
| `PWD` | The current working directory. This variable stores the full path to the directory that the user is currently working in. This can be useful for scripting and automation tasks. |
10+
| `SHELL` | The path to the current user's default shell. This variable stores the path to the shell that is currently running. This can be useful for shell scripts that need to know which shell is being used. |

doc/tags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
edit-markdown-table edit-markdown-table.txt /*edit-markdown-table-contents*

lua/edit-markdown-table/init.lua

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
local M = {}
2+
3+
M.setup = function()
4+
vim.cmd([[ command! EditMarkdownTable lua require('edit-markdown-table').edit_cell() ]])
5+
end
6+
7+
--- Opens a dialog to edit the cell within the markdown table
8+
--- located within the current cursor.
9+
M.edit_cell = function()
10+
local node = vim.treesitter.get_node()
11+
if node == nil then
12+
return
13+
end
14+
15+
local node_type = node:type()
16+
if node_type ~= "pipe_table_cell" and node_type ~= "pipe_table_header" then
17+
return
18+
end
19+
20+
local current_buffer_number = 0
21+
local current_contents = vim.treesitter.get_node_text(node, current_buffer_number)
22+
23+
vim.ui.input({
24+
prompt = "edit>",
25+
default = current_contents,
26+
}, function(input)
27+
-- if the user presses esc
28+
if input == nil then
29+
return
30+
end
31+
32+
local start_row, start_col, end_row, end_col = node:range()
33+
vim.api.nvim_buf_set_text(current_buffer_number, start_row, start_col, end_row, end_col, { input })
34+
end)
35+
end
36+
37+
return M

makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
run:
2+
nvim --cmd "set rtp+=./" -o lua/edit-markdown-table/init.lua -o doc/example.md
3+
4+
help:
5+
nvim --cmd "set rtp+=./" --cmd 'h edit-markdown-table'
6+
7+
update_doc:
8+
md2vim README.md doc/edit-markdown-table.txt
9+
10+
install_deps:
11+
# used to convert markdown to vimdoc
12+
go install foosoft.net/projects/md2vim@latest

0 commit comments

Comments
 (0)