Skip to content

Commit c221998

Browse files
Add support for dynamically changing conceallevel between rendered and raw views
# Details Brought up in #10, it would be cool if we could conceal links when rendering markdown. Turns out if conceallevel is set to a high enough value this happens by default. Hook into this existing feature be increasing conceallevel to 3 when rendering markdown, and use user default value in all other cases. Allow individuals to opt out of this by changing the conceallevel values for both default and rendered.
1 parent df59836 commit c221998

File tree

6 files changed

+26
-2
lines changed

6 files changed

+26
-2
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ Plugin to improve viewing Markdown files in Neovim
77
# Features
88

99
- Functions entirely inside of Neovim with no external windows
10-
- Changes between `rendered` view in normal mode and raw view in all other modes
10+
- Changes between `rendered` view in normal mode and `raw` view in all other modes
11+
- Changes `conceallevel` between `rendered` and `raw` view based on configuration
1112
- Supports rendering `markdown` injected into other file types
1213
- Highlights headings with different groups depending on level and replaces `#`
1314
- Highlights code blocks and inline code to better stand out
@@ -87,6 +88,13 @@ require('render-markdown').setup({
8788
bullet = '',
8889
-- Character that will replace the > at the start of block quotes
8990
quote = '',
91+
-- See :h 'conceallevel' for more information about meaning of values
92+
conceal = {
93+
-- conceallevel used for buffer when not being rendered, get user setting
94+
default = vim.opt.conceallevel:get(),
95+
-- conceallevel used for buffer when being rendered
96+
rendered = 3,
97+
},
9098
-- Define the highlight groups to use when rendering various components
9199
highlights = {
92100
heading = {

demo/demo.gif

24.9 KB
Loading

demo/sample.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ if __name__ == "__main__":
2020
main()
2121
```
2222

23-
- List Item 1
23+
- List Item 1: with [link](https://example.com)
2424
* List Item 2: with `inline` code
2525
* Nested List Item 1
2626
* Nested List Item 2

lua/render-markdown/init.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ local M = {}
1919
---@field public latex? string
2020
---@field public quote? string
2121

22+
---@class UserConceal
23+
---@field public default? integer
24+
---@field public rendered? integer
25+
2226
---@class UserConfig
2327
---@field public markdown_query? string
2428
---@field public inline_query? string
@@ -27,6 +31,7 @@ local M = {}
2731
---@field public headings? string[]
2832
---@field public bullet? string
2933
---@field public quote? string
34+
---@field public conceal? UserConceal
3035
---@field public highlights? UserHighlights
3136

3237
---@param opts UserConfig|nil
@@ -66,6 +71,10 @@ function M.setup(opts)
6671
headings = { '󰲡 ', '󰲣 ', '󰲥 ', '󰲧 ', '󰲩 ', '󰲫 ' },
6772
bullet = '',
6873
quote = '',
74+
conceal = {
75+
default = vim.opt.conceallevel:get(),
76+
rendered = 3,
77+
},
6978
highlights = {
7079
heading = {
7180
backgrounds = { 'DiffAdd', 'DiffChange', 'DiffDelete' },

lua/render-markdown/state.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
---@field public latex string
1515
---@field public quote string
1616

17+
---@class Conceal
18+
---@field public default integer
19+
---@field public rendered integer
20+
1721
---@class Config
1822
---@field public markdown_query string
1923
---@field public inline_query string
@@ -22,6 +26,7 @@
2226
---@field public headings string[]
2327
---@field public bullet string
2428
---@field public quote string
29+
---@field public conceal Conceal
2530
---@field public highlights Highlights
2631

2732
---@class State

lua/render-markdown/ui.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ M.namespace = vim.api.nvim_create_namespace('render-markdown.nvim')
88
M.clear = function()
99
-- Remove existing highlights / virtual text
1010
vim.api.nvim_buf_clear_namespace(0, M.namespace, 0, -1)
11+
vim.opt_local.conceallevel = state.config.conceal.default
1112
end
1213

1314
M.refresh = function()
@@ -23,6 +24,7 @@ M.refresh = function()
2324
return
2425
end
2526

27+
vim.opt_local.conceallevel = state.config.conceal.rendered
2628
vim.treesitter.get_parser():for_each_tree(function(tree, language_tree)
2729
local language = language_tree:lang()
2830
if language == 'markdown' then

0 commit comments

Comments
 (0)