Skip to content

Commit 53092a0

Browse files
Update changelog, link demo, minor refactor to link logic
1 parent d5b57b3 commit 53092a0

File tree

5 files changed

+39
-38
lines changed

5 files changed

+39
-38
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@
3535
[4d8b603](https://github.com/MeanderingProgrammer/markdown.nvim/commit/4d8b6032b659a45582089de8bcd839f8ccc4161d)
3636
- Obsidian like custom callout titles [#109](https://github.com/MeanderingProgrammer/markdown.nvim/issues/109)
3737
[a1bcbf4](https://github.com/MeanderingProgrammer/markdown.nvim/commit/a1bcbf4858d1834f922029b5fc6ae55a7417bd51)
38+
- Support for wikilinks [e6695b4](https://github.com/MeanderingProgrammer/markdown.nvim/commit/e6695b4ff330cf9c216fe5e40491cee39d93383a)
39+
- Skip parsing when no text changes and already parsed [#115](https://github.com/MeanderingProgrammer/markdown.nvim/issues/115)
40+
[6bb1d43](https://github.com/MeanderingProgrammer/markdown.nvim/commit/6bb1d43c9e360929d4497a0459084b062bfe9de5)
41+
- Callouts on wrapped lines kind of [#114](https://github.com/MeanderingProgrammer/markdown.nvim/issues/114)
42+
[66110dd](https://github.com/MeanderingProgrammer/markdown.nvim/commit/66110ddfc27b8785f3046dcf516a4f75d6a8f0f9)
43+
- Custom link icons based on destination [#117](https://github.com/MeanderingProgrammer/markdown.nvim/issues/117)
44+
[d5b57b3](https://github.com/MeanderingProgrammer/markdown.nvim/commit/d5b57b32397c0be1f511f4cdf2b876c5b1f01144)
3845

3946
### Bug Fixes
4047

@@ -48,6 +55,10 @@
4855

4956
- @scottmckendry
5057

58+
### Awesome Things
59+
60+
- Supported by catppuccin colorscheme [#740](https://github.com/catppuccin/nvim/pull/740)
61+
5162
## 5.0.0 (2024-07-27)
5263

5364
### ⚠ BREAKING CHANGES

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Plugin to improve viewing Markdown files in Neovim
66

77
| | |
88
| -------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
9-
| ![Heading Code](https://github.com/user-attachments/assets/663a34c5-0438-4688-8204-332065f65835) | ![List Table](https://github.com/user-attachments/assets/106739a4-506f-4177-93e0-fd749e5ded5c) |
9+
| ![Heading Code](https://github.com/user-attachments/assets/663a34c5-0438-4688-8204-332065f65835) | ![List Table](https://github.com/user-attachments/assets/162986e1-91f0-4e13-a83f-6183d58b0fcb) |
1010
| ![Box Dash Quote](https://github.com/user-attachments/assets/3f76e73e-b3a0-4cd8-90c1-208c5070659c) | ![LaTeX](https://github.com/user-attachments/assets/9e8909e4-7256-45fc-b481-4aba8850ebc3) |
1111
| ![Callout](https://github.com/user-attachments/assets/4324ea72-a017-4175-9f9d-363da5e5f6ba) | |
1212

doc/todo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
- See if there is a stable way to align table cells according to delimiter
44
alignment info.
5-
- Figure out how to display the many configuration options & impact
5+
- Figure out how to display the many configuration options & impact, Wiki in progress
66
- Potentially change LuaRocks icon dependency to [mini.icons](https://luarocks.org/modules/neorocks/mini.icons)

lua/render-markdown/component.lua

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,4 @@ function M.checkbox(config, text, comparison)
4949
return nil
5050
end
5151

52-
---@param config render.md.BufferConfig
53-
---@param text string
54-
---@return render.md.LinkComponent?
55-
function M.link(config, text)
56-
for _, component in pairs(config.link.custom) do
57-
if text:find(component.pattern) then
58-
return component
59-
end
60-
end
61-
return nil
62-
end
63-
6452
return M

lua/render-markdown/handler/markdown_inline.lua

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ function Handler:wiki_link(info)
158158
end
159159
local text = info.text:sub(2, -2)
160160
local parts = str.split(text, '|')
161-
local icon, highlight = self:destination_info(parts[1])
161+
local icon, highlight = self:dest_virt_text(parts[1])
162162
---@type render.md.Mark
163163
return {
164164
conceal = true,
@@ -178,26 +178,11 @@ end
178178
---@param info render.md.NodeInfo
179179
---@return render.md.Mark?
180180
function Handler:link(info)
181-
local link = self.config.link
182181
-- Requires inline extmarks
183-
if not link.enabled or not util.has_10 then
184-
return nil
185-
end
186-
local icon, highlight
187-
if info.type == 'inline_link' then
188-
local destination = ts.child(self.buf, info, 'link_destination')
189-
if destination ~= nil then
190-
icon, highlight = self:destination_info(destination.text)
191-
else
192-
icon, highlight = link.hyperlink, link.highlight
193-
end
194-
elseif info.type == 'full_reference_link' then
195-
icon, highlight = link.hyperlink, link.highlight
196-
elseif info.type == 'image' then
197-
icon, highlight = link.image, link.highlight
198-
else
182+
if not self.config.link.enabled or not util.has_10 then
199183
return nil
200184
end
185+
local icon, highlight = self:link_virt_text(info)
201186
context.get(self.buf):add_link(info, icon)
202187
---@type render.md.Mark
203188
return {
@@ -213,16 +198,33 @@ function Handler:link(info)
213198
}
214199
end
215200

201+
---@private
202+
---@param info render.md.NodeInfo
203+
---@return string, string
204+
function Handler:link_virt_text(info)
205+
local link = self.config.link
206+
if info.type == 'image' then
207+
return link.image, link.highlight
208+
elseif info.type == 'inline_link' then
209+
local destination = ts.child(self.buf, info, 'link_destination')
210+
if destination ~= nil then
211+
return self:dest_virt_text(destination.text)
212+
end
213+
end
214+
return link.hyperlink, link.highlight
215+
end
216+
216217
---@private
217218
---@param destination string
218219
---@return string, string
219-
function Handler:destination_info(destination)
220-
local link_component = component.link(self.config, destination)
221-
if link_component == nil then
222-
return self.config.link.hyperlink, self.config.link.highlight
223-
else
224-
return link_component.icon, link_component.highlight
220+
function Handler:dest_virt_text(destination)
221+
local link = self.config.link
222+
for _, link_component in pairs(link.custom) do
223+
if destination:find(link_component.pattern) then
224+
return link_component.icon, link_component.highlight
225+
end
225226
end
227+
return link.hyperlink, link.highlight
226228
end
227229

228230
---@class render.md.handler.MarkdownInline: render.md.Handler

0 commit comments

Comments
 (0)