Skip to content

Commit 74502e5

Browse files
feat: add icon to emails
1 parent 2f32e71 commit 74502e5

File tree

10 files changed

+96
-76
lines changed

10 files changed

+96
-76
lines changed

README.md

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,34 +31,31 @@ Plugin to improve viewing Markdown files in Neovim
3131
3232
# Features
3333
34-
- Functions entirely inside of Neovim with no external windows
35-
- Changes between `rendered` view in normal mode and `raw` view in all other modes
36-
- Supports anti-conceal behavior, removing any virtual text added by this plugin
37-
on the line the cursor is on, this can be disabled
38-
- Changes window options between `rendered` and `raw` view based on configuration
39-
- Effects `conceallevel` & `concealcursor` by default
40-
- Supports rendering `markdown` injected into any file type
41-
- Renders the following `markdown` components:
42-
- Headings: highlight depending on level and replaces `#` with icon
43-
- Horizontal breaks: replace with full-width lines
44-
- Code blocks: highlight to better stand out
45-
- Adds language icon [^1], requires icon provider (`mini.icons` or `nvim-web-devicons`)
46-
- Left pad lines within block [^1]
47-
- Inline code: highlight to better stand out
48-
- List bullet points: replace with provided icon based on level
49-
- Checkboxes: replace with provided icon based on whether they are checked
50-
- Block quotes: replace leading `>` with provided icon
51-
- Tables: replace border characters, handles misaligned tables but does NOT align
52-
according to delimiter indicator
53-
- [Callouts](https://github.com/orgs/community/discussions/16925): Github & Obsidian
54-
out of the box, supports user defined as well
55-
- Custom checkbox states [^1], function similar to `callouts`
56-
- Adds icon before images / links [^1]
57-
- `LaTeX` blocks: renders formulas if `latex` parser and `pylatexenc` are installed
58-
- Disable rendering when file is larger than provided value
59-
- Support custom handlers which are ran identically to builtin handlers
34+
- Contained: runs entirely inside Neovim with no external windows
35+
- Configurable: all components, padding, icons, and colors can be modified
36+
- File type agnostic: can render `markdown` injected into any file
37+
- Mode based rendering: changes between `rendered` and `raw` view based on mode
38+
- Anti-conceal: hides virtual text added by this plugin on cursor line
39+
- Window options: changes option values between `rendered` and `raw` view
40+
- Large files: only renders visisble range, can be entirely disabled based on size
41+
- Custom rendering: provides extension point where user can add anything
42+
- Renders the following `markdown` components out of the box:
43+
- Headings: icon, color, border, padding [^1], width
44+
- Code blocks: background, language icon [^1] [^2], border, padding [^1], width
45+
- Code inline: background
46+
- Horizontal breaks: icon, color, width
47+
- List bullets: icon, color, padding [^1]
48+
- Checkboxes: icon, color, user defined states [^1]
49+
- Block quotes: icon, color, line breaks [^1]
50+
- Callouts: icon, color, user defined values, Github & Obsidian defaults
51+
- Tables: border, color, alignment indicator, auto align cells always to left [^1]
52+
- Links [^1]: icon, color, user defined destinations
53+
- `LaTeX` blocks [^3]: renders formulas
54+
- Org indent mode [^1]: per level padding
6055
6156
[^1]: Requires neovim >= `0.10.0`
57+
[^2]: Requires icon provider, `mini.icons` or `nvim-web-devicons`
58+
[^3]: Requires `latex` parser and `pylatexenc`
6259
6360
# Requirements
6461
@@ -199,7 +196,12 @@ require('render-markdown').setup({
199196
200197
(shortcut_link) @shortcut
201198
202-
[(inline_link) (full_reference_link) (image)] @link
199+
[
200+
(image)
201+
(email_autolink)
202+
(inline_link)
203+
(full_reference_link)
204+
] @link
203205
]],
204206
-- The level of logs to write to file: vim.fn.stdpath('state') .. '/render-markdown.log'
205207
-- Only intended to be used for plugin development / debugging
@@ -470,6 +472,8 @@ require('render-markdown').setup({
470472
enabled = true,
471473
-- Inlined with 'image' elements
472474
image = '󰥶 ',
475+
-- Inlined with 'email_autolink' elements
476+
email = '󰀓 ',
473477
-- Fallback icon for 'inline_link' elements
474478
hyperlink = '󰌹 ',
475479
-- Applies to the fallback inlined icon
@@ -861,6 +865,8 @@ require('render-markdown').setup({
861865
enabled = true,
862866
-- Inlined with 'image' elements
863867
image = '󰥶 ',
868+
-- Inlined with 'email_autolink' elements
869+
email = '󰀓 ',
864870
-- Fallback icon for 'inline_link' elements
865871
hyperlink = '󰌹 ',
866872
-- Applies to the fallback inlined icon

doc/render-markdown.txt

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For 0.10.0 Last change: 2024 August 22
1+
*render-markdown.txt* For 0.10.0 Last change: 2024 August 23
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*
@@ -52,32 +52,27 @@ Plugin to improve viewing Markdown files in Neovim
5252
==============================================================================
5353
2. Features *render-markdown-features*
5454

55-
- Functions entirely inside of Neovim with no external windows
56-
- Changes between `rendered` view in normal mode and `raw` view in all other modes
57-
- Supports anti-conceal behavior, removing any virtual text added by this plugin
58-
on the line the cursor is on, this can be disabled
59-
- Changes window options between `rendered` and `raw` view based on configuration
60-
- Effects `conceallevel` & `concealcursor` by default
61-
- Supports rendering `markdown` injected into any file type
62-
- Renders the following `markdown` components:
63-
- Headings: highlight depending on level and replaces `#` with icon
64-
- Horizontal breaks: replace with full-width lines
65-
- Code blocks: highlight to better stand out
66-
- Adds language icon , requires icon provider (`mini.icons` or `nvim-web-devicons`)
67-
- Left pad lines within block
68-
- Inline code: highlight to better stand out
69-
- List bullet points: replace with provided icon based on level
70-
- Checkboxes: replace with provided icon based on whether they are checked
71-
- Block quotes: replace leading `>` with provided icon
72-
- Tables: replace border characters, handles misaligned tables but does NOT align
73-
according to delimiter indicator
74-
- Callouts <https://github.com/orgs/community/discussions/16925>: Github & Obsidian
75-
out of the box, supports user defined as well
76-
- Custom checkbox states , function similar to `callouts`
77-
- Adds icon before images / links
78-
- `LaTeX` blocks: renders formulas if `latex` parser and `pylatexenc` are installed
79-
- Disable rendering when file is larger than provided value
80-
- Support custom handlers which are ran identically to builtin handlers
55+
- Contained: runs entirely inside Neovim with no external windows
56+
- Configurable: all components, padding, icons, and colors can be modified
57+
- File type agnostic: can render `markdown` injected into any file
58+
- Mode based rendering: changes between `rendered` and `raw` view based on mode
59+
- Anti-conceal: hides virtual text added by this plugin on cursor line
60+
- Window options: changes option values between `rendered` and `raw` view
61+
- Large files: only renders visisble range, can be entirely disabled based on size
62+
- Custom rendering: provides extension point where user can add anything
63+
- Renders the following `markdown` components out of the box:
64+
- Headings: icon, color, border, padding , width
65+
- Code blocks: background, language icon , border, padding , width
66+
- Code inline: background
67+
- Horizontal breaks: icon, color, width
68+
- List bullets: icon, color, padding
69+
- Checkboxes: icon, color, user defined states
70+
- Block quotes: icon, color, line breaks
71+
- Callouts: icon, color, user defined values, Github & Obsidian defaults
72+
- Tables: border, color, alignment indicator, auto align cells always to left
73+
- Links : icon, color, user defined destinations
74+
- `LaTeX` blocks : renders formulas
75+
- Org indent mode : per level padding
8176

8277

8378
==============================================================================
@@ -230,7 +225,12 @@ Full Default Configuration ~
230225

231226
(shortcut_link) @shortcut
232227

233-
[(inline_link) (full_reference_link) (image)] @link
228+
[
229+
(image)
230+
(email_autolink)
231+
(inline_link)
232+
(full_reference_link)
233+
] @link
234234
]],
235235
-- The level of logs to write to file: vim.fn.stdpath('state') .. '/render-markdown.log'
236236
-- Only intended to be used for plugin development / debugging
@@ -501,6 +501,8 @@ Full Default Configuration ~
501501
enabled = true,
502502
-- Inlined with 'image' elements
503503
image = '󰥶 ',
504+
-- Inlined with 'email_autolink' elements
505+
email = '󰀓 ',
504506
-- Fallback icon for 'inline_link' elements
505507
hyperlink = '󰌹 ',
506508
-- Applies to the fallback inlined icon
@@ -908,6 +910,8 @@ Wiki Page
908910
enabled = true,
909911
-- Inlined with 'image' elements
910912
image = '󰥶 ',
913+
-- Inlined with 'email_autolink' elements
914+
email = '󰀓 ',
911915
-- Fallback icon for 'inline_link' elements
912916
hyperlink = '󰌹 ',
913917
-- Applies to the fallback inlined icon

lua/render-markdown/handler/markdown_inline.lua

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,25 +158,28 @@ function Handler:link(info)
158158
if not self.config.link.enabled then
159159
return
160160
end
161-
local icon, highlight = self:link_virt_text(info)
161+
local link_text, highlight, conceal = self:link_virt_text(info)
162162
local added = self.marks:add(true, info.start_row, info.start_col, {
163163
end_row = info.end_row,
164164
end_col = info.end_col,
165-
virt_text = { { icon, highlight } },
165+
virt_text = { { link_text, highlight } },
166166
virt_text_pos = 'inline',
167+
conceal = conceal,
167168
})
168-
if added then
169-
self.context:add_offset(info, str.width(icon))
169+
if conceal == nil and added then
170+
self.context:add_offset(info, str.width(link_text))
170171
end
171172
end
172173

173174
---@private
174175
---@param info render.md.NodeInfo
175-
---@return string, string
176+
---@return string, string, string?
176177
function Handler:link_virt_text(info)
177178
local link = self.config.link
178179
if info.type == 'image' then
179180
return link.image, link.highlight
181+
elseif info.type == 'email_autolink' then
182+
return link.email .. info.text:sub(2, -2), link.highlight, ''
180183
elseif info.type == 'inline_link' then
181184
local destination = info:child('link_destination')
182185
if destination ~= nil then

lua/render-markdown/health.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local M = {}
55

66
---@private
77
---@type string
8-
M.version = '6.2.4'
8+
M.version = '6.2.5'
99

1010
function M.check()
1111
vim.health.start('render-markdown.nvim [version]')

lua/render-markdown/init.lua

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ local M = {}
3838
---@class (exact) render.md.UserLink
3939
---@field public enabled? boolean
4040
---@field public image? string
41+
---@field public email? string
4142
---@field public hyperlink? string
4243
---@field public highlight? string
4344
---@field public custom? table<string, render.md.UserLinkComponent>
@@ -239,7 +240,12 @@ M.default_config = {
239240
240241
(shortcut_link) @shortcut
241242
242-
[(inline_link) (full_reference_link) (image)] @link
243+
[
244+
(image)
245+
(email_autolink)
246+
(inline_link)
247+
(full_reference_link)
248+
] @link
243249
]],
244250
-- The level of logs to write to file: vim.fn.stdpath('state') .. '/render-markdown.log'
245251
-- Only intended to be used for plugin development / debugging
@@ -510,6 +516,8 @@ M.default_config = {
510516
enabled = true,
511517
-- Inlined with 'image' elements
512518
image = '󰥶 ',
519+
-- Inlined with 'email_autolink' elements
520+
email = '󰀓 ',
513521
-- Fallback icon for 'inline_link' elements
514522
hyperlink = '󰌹 ',
515523
-- Applies to the fallback inlined icon

lua/render-markdown/state.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ function M.validate()
353353
append_errors(path .. '.link', link, {
354354
enabled = { link.enabled, 'boolean', nilable },
355355
image = { link.image, 'string', nilable },
356+
email = { link.email, 'string', nilable },
356357
hyperlink = { link.hyperlink, 'string', nilable },
357358
highlight = { link.highlight, 'string', nilable },
358359
custom = { link.custom, 'table', nilable },

lua/render-markdown/types.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
---@class (exact) render.md.Link
2828
---@field public enabled boolean
2929
---@field public image string
30+
---@field public email string
3031
---@field public hyperlink string
3132
---@field public highlight string
3233
---@field public custom table<string, render.md.LinkComponent>

tests/ad_hoc_spec.lua

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
local util = require('tests.util')
44

55
---@param row integer
6-
---@param start_col integer
7-
---@param end_col integer
8-
---@param text string
6+
---@param col integer
7+
---@param link_text string
98
---@return render.md.MarkInfo
10-
local function wiki_link(row, start_col, end_col, text)
9+
local function conceal_link(row, col, link_text)
1110
---@type render.md.MarkInfo
1211
return {
1312
row = { row, row },
14-
col = { start_col, end_col },
15-
virt_text = { { '󰌹 ' .. text, util.hl('Link') } },
13+
col = { 0, col },
14+
virt_text = { { link_text, util.hl('Link') } },
1615
virt_text_pos = 'inline',
1716
conceal = '',
1817
}
@@ -27,8 +26,9 @@ describe('ad_hoc.md', function()
2726
vim.list_extend(expected, util.heading(row:get(), 1))
2827

2928
vim.list_extend(expected, {
30-
wiki_link(row:increment(4), 0, 13, 'Basic One'),
31-
wiki_link(row:increment(2), 0, 23, 'With Alias'),
29+
conceal_link(row:increment(4), 13, '󰌹 Basic One'),
30+
conceal_link(row:increment(2), 23, '󰌹 With Alias'),
31+
conceal_link(row:increment(2), 18, '󰀓 [email protected]'),
3232
})
3333

3434
local actual = util.get_actual_marks()

tests/data/ad_hoc.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
[[Basic One]] Then normal text
66

77
[[Nickname|With Alias]] Something important
8+
9+

tests/util.lua

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,7 @@ end
223223
---@param head boolean
224224
---@return render.md.MarkInfo
225225
function M.table_pipe(row, col, head)
226-
local highlight
227-
if head then
228-
highlight = 'TableHead'
229-
else
230-
highlight = 'TableRow'
231-
end
226+
local highlight = head and 'TableHead' or 'TableRow'
232227
---@type render.md.MarkInfo
233228
return {
234229
row = { row, row },

0 commit comments

Comments
 (0)