Skip to content

Commit

Permalink
Fix markdown quotes
Browse files Browse the repository at this point in the history
fix #52
  • Loading branch information
lukas-reineke committed Nov 13, 2023
1 parent 74a083a commit e3d7bfd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 23 deletions.
34 changes: 18 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@ Use your favourite plugin manager to install.

```lua
-- init.lua
require("packer").startup(
function()
use {
'lukas-reineke/headlines.nvim',
after = 'nvim-treesitter',
config = function()
require('headlines').setup()
end,
}
end
)
require("packer").startup(function()
use {
"lukas-reineke/headlines.nvim",
after = "nvim-treesitter",
config = function()
require("headlines").setup()
end,
}
end)
```

#### Example with Plug
Expand All @@ -53,13 +51,13 @@ EOF

```lua
-- init.lua
require('lazy').setup({
require("lazy").setup {
{
'lukas-reineke/headlines.nvim',
"lukas-reineke/headlines.nvim",
dependencies = "nvim-treesitter/nvim-treesitter",
config = true, -- or `opts = {}`
}
})
},
}
```

## Setup
Expand Down Expand Up @@ -91,6 +89,8 @@ require("headlines").setup {
(block_quote_marker) @quote
(block_quote (paragraph (inline (block_continuation) @quote)))
(block_quote (paragraph (block_continuation) @quote))
(block_quote (block_continuation) @quote)
]]
),
headline_highlights = { "Headline" },
Expand Down Expand Up @@ -122,6 +122,8 @@ require("headlines").setup {
(block_quote_marker) @quote
(block_quote (paragraph (inline (block_continuation) @quote)))
(block_quote (paragraph (block_continuation) @quote))
(block_quote (block_continuation) @quote)
]]
),
treesitter_language = "markdown",
Expand Down Expand Up @@ -229,7 +231,7 @@ require("headlines").setup {
]]
),
dash_highlight = "Dash",
}
},
}
```

Expand Down
27 changes: 20 additions & 7 deletions lua/headlines/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ M.config = {
(block_quote_marker) @quote
(block_quote (paragraph (inline (block_continuation) @quote)))
(block_quote (paragraph (block_continuation) @quote))
(block_quote (block_continuation) @quote)
]]
),
headline_highlights = { "Headline" },
Expand Down Expand Up @@ -66,6 +68,8 @@ M.config = {
(block_quote_marker) @quote
(block_quote (paragraph (inline (block_continuation) @quote)))
(block_quote (paragraph (block_continuation) @quote))
(block_quote (block_continuation) @quote)
]]
),
treesitter_language = "markdown",
Expand Down Expand Up @@ -225,7 +229,7 @@ M.refresh = function()
for _, match, metadata in c.query:iter_matches(root, bufnr) do
for id, node in pairs(match) do
local capture = c.query.captures[id]
local start_row, start_column, end_row, _ =
local start_row, start_column, end_row, end_column =
unpack(vim.tbl_extend("force", { node:range() }, (metadata[id] or {}).range or {}))

if capture == "headline" and c.headline_highlights then
Expand Down Expand Up @@ -307,7 +311,7 @@ M.refresh = function()
local codeblock_padding = math.max((padding or 0) - left_offset, 0)

if codeblock_padding > 0 then
for i = start_row, end_row do
for i = start_row, end_row - 1 do
nvim_buf_set_extmark(bufnr, M.namespace, i, 0, {
virt_text = { { string.rep(" ", codeblock_padding), "Normal" } },
virt_text_win_col = 0,
Expand All @@ -318,11 +322,20 @@ M.refresh = function()
end

if capture == "quote" and c.quote_highlight and c.quote_string then
nvim_buf_set_extmark(bufnr, M.namespace, start_row, start_column, {
virt_text = { { c.quote_string, c.quote_highlight } },
virt_text_pos = "overlay",
hl_mode = "combine",
})
if vim.bo.filetype == "markdown" then
local text = vim.api.nvim_buf_get_text(bufnr, start_row, start_column, end_row, end_column, {})[1]
nvim_buf_set_extmark(bufnr, M.namespace, start_row, start_column, {
virt_text = { { text:gsub(">", c.quote_string), c.quote_highlight } },
virt_text_pos = "overlay",
hl_mode = "combine",
})
else
nvim_buf_set_extmark(bufnr, M.namespace, start_row, start_column, {
virt_text = { { c.quote_string, c.quote_highlight } },
virt_text_pos = "overlay",
hl_mode = "combine",
})
end
end
end
end
Expand Down

0 comments on commit e3d7bfd

Please sign in to comment.