Skip to content

Commit 4d8e991

Browse files
feat: allow individual components to specify additional render modes
## Details Request: #269 Previously the only level of control users had was what modes to perform rendering in and what components (headings, code blocks, etc.) should be rendered when we do this. This is a good amount of control however some users would prefer to have a cleaner experience in insert mode while doing a subset of the rendering done in normal mode. To make this possible was a decent refactor but actually not too bad because of how information is centralized in a couple key objects. For users the way this works is the current top level `render_modes` value now defines the set of modes where all enabled components are rendered. Now in addition to this each individual component has its own `render_modes` config which can specify additional modes (or all with a boolean) in which only these components will be rendered. So the workflow to decide rendering is now: - Is component enabled - Is the current mode in the top level config - If not check if the mode is defined in the component level configuration - Any unmatched components are skipped Also needed to alter the logic to decide is the current mode rendered or not. It is now the super set of all modes defined in the top level configuration plus any defined within components. This does not matter for the most part but does alter the events we listen on (if a component needs to be rendered in insert mode we need to listen to insert mode text changes now) along with the window options we set, most importantly the conceallevel will remain at the rendered level since this is important for many rendering features. Example: ```lua require('render-markdown').setup({ render_modes = { 'n', 'c', 't' }, heading = { render_modes = { 'i' } }, code = { render_modes = { 'i' } }, }) ``` With this configuration all components will be rendered in `normal`, `command`, and `terminal` modes, additionally headings and code blocks will be rendered in `insert` mode, but no others. The default value for every component's `render_modes` is set to `false`, which is equivalent to the empty list. This means by default nothing is changed and we continue to render according to only the top level `render_modes` value. Some other minor things needed to change but nothing of particular note.
1 parent c00cc1e commit 4d8e991

27 files changed

+310
-103
lines changed

Diff for: README.md

+51-4
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ Some of the more useful fields are discussed further down.
173173
require('render-markdown').setup({
174174
-- Whether Markdown should be rendered by default or not
175175
enabled = true,
176+
-- Vim modes that will show a rendered view of the markdown file, :h mode(), for
177+
-- all enabled components. Individual components can be enabled for other modes.
178+
-- Remaining modes will be unaffected by this plugin.
179+
render_modes = { 'n', 'c', 't' },
176180
-- Maximum file size (in MB) that this plugin will attempt to render
177181
-- Any file larger than this will effectively be ignored
178182
max_file_size = 10.0,
@@ -207,9 +211,6 @@ require('render-markdown').setup({
207211
]],
208212
},
209213
},
210-
-- Vim modes that will show a rendered view of the markdown file, :h mode()
211-
-- All other modes will be unaffected by this plugin
212-
render_modes = { 'n', 'c', 't' },
213214
anti_conceal = {
214215
-- This enables hiding any added text on the line the cursor is on
215216
enabled = true,
@@ -234,6 +235,8 @@ require('render-markdown').setup({
234235
latex = {
235236
-- Whether LaTeX should be rendered, mainly used for health check
236237
enabled = true,
238+
-- Additional modes to render LaTeX
239+
render_modes = false,
237240
-- Executable used to convert latex formula to rendered unicode
238241
converter = 'latex2text',
239242
-- Highlight for LaTeX blocks
@@ -252,6 +255,8 @@ require('render-markdown').setup({
252255
heading = {
253256
-- Turn on / off heading icon & background rendering
254257
enabled = true,
258+
-- Additional modes to render headings
259+
render_modes = false,
255260
-- Turn on / off any sign column related rendering
256261
sign = true,
257262
-- Determines how icons fill the available space:
@@ -323,6 +328,8 @@ require('render-markdown').setup({
323328
paragraph = {
324329
-- Turn on / off paragraph rendering
325330
enabled = true,
331+
-- Additional modes to render paragraphs
332+
render_modes = false,
326333
-- Amount of margin to add to the left of paragraphs
327334
-- If a floating point value < 1 is provided it is treated as a percentage of the available window space
328335
left_margin = 0,
@@ -332,6 +339,8 @@ require('render-markdown').setup({
332339
code = {
333340
-- Turn on / off code block & inline code rendering
334341
enabled = true,
342+
-- Additional modes to render code blocks
343+
render_modes = false,
335344
-- Turn on / off any sign column related rendering
336345
sign = true,
337346
-- Determines how code blocks & inline code are rendered:
@@ -391,6 +400,8 @@ require('render-markdown').setup({
391400
dash = {
392401
-- Turn on / off thematic break rendering
393402
enabled = true,
403+
-- Additional modes to render dash
404+
render_modes = false,
394405
-- Replaces '---'|'***'|'___'|'* * *' of 'thematic_break'
395406
-- The icon gets repeated across the window's width
396407
icon = '',
@@ -408,6 +419,8 @@ require('render-markdown').setup({
408419
bullet = {
409420
-- Turn on / off list bullet rendering
410421
enabled = true,
422+
-- Additional modes to render list bullets
423+
render_modes = false,
411424
-- Replaces '-'|'+'|'*' of 'list_item'
412425
-- How deeply nested the list is determines the 'level', how far down at that level determines the 'index'
413426
-- If a function is provided both of these values are passed in using 1 based indexing
@@ -437,6 +450,8 @@ require('render-markdown').setup({
437450
checkbox = {
438451
-- Turn on / off checkbox state rendering
439452
enabled = true,
453+
-- Additional modes to render checkboxes
454+
render_modes = false,
440455
-- Determines how icons fill the available space:
441456
-- inline: underlying text is concealed resulting in a left aligned icon
442457
-- overlay: result is left padded with spaces to hide any additional text
@@ -472,6 +487,8 @@ require('render-markdown').setup({
472487
quote = {
473488
-- Turn on / off block quote & callout rendering
474489
enabled = true,
490+
-- Additional modes to render quotes
491+
render_modes = false,
475492
-- Replaces '>' of 'block_quote'
476493
icon = '',
477494
-- Whether to repeat icon on wrapped lines. Requires neovim >= 0.10. This will obscure text if
@@ -486,6 +503,8 @@ require('render-markdown').setup({
486503
pipe_table = {
487504
-- Turn on / off pipe table rendering
488505
enabled = true,
506+
-- Additional modes to render pipe tables
507+
render_modes = false,
489508
-- Pre configured settings largely for setting table border easier
490509
-- heavy: use thicker border characters
491510
-- double: use double line border characters
@@ -565,6 +584,8 @@ require('render-markdown').setup({
565584
link = {
566585
-- Turn on / off inline link icon rendering
567586
enabled = true,
587+
-- Additional modes to render links
588+
render_modes = false,
568589
-- How to handle footnote links, start with a '^'
569590
footnote = {
570591
-- Replace value with superscript equivalent
@@ -613,6 +634,8 @@ require('render-markdown').setup({
613634
inline_highlight = {
614635
-- Turn on / off inline highlight rendering
615636
enabled = true,
637+
-- Additional modes to render inline highlights
638+
render_modes = false,
616639
-- Applies to background of surrounded text
617640
highlight = 'RenderMarkdownInlineHighlight',
618641
},
@@ -621,6 +644,8 @@ require('render-markdown').setup({
621644
indent = {
622645
-- Turn on / off org-indent-mode
623646
enabled = false,
647+
-- Additional modes to render indents
648+
render_modes = false,
624649
-- Amount of additional padding added for each heading level
625650
per_level = 2,
626651
-- Heading levels <= this value will not be indented
@@ -632,6 +657,8 @@ require('render-markdown').setup({
632657
html = {
633658
-- Turn on / off all HTML rendering
634659
enabled = true,
660+
-- Additional modes to render HTML
661+
render_modes = false,
635662
comment = {
636663
-- Turn on / off HTML comment concealing
637664
conceal = true,
@@ -663,7 +690,7 @@ require('render-markdown').setup({
663690
-- if no override is provided. Supports the following fields:
664691
-- enabled, max_file_size, debounce, render_modes, anti_conceal, padding,
665692
-- heading, paragraph, code, dash, bullet, checkbox, quote, pipe_table,
666-
-- callout, link, sign, indent, html, win_options
693+
-- callout, link, sign, indent, latex, html, win_options
667694
overrides = {
668695
-- Overrides for different buftypes, see :h 'buftype'
669696
buftype = {
@@ -703,6 +730,8 @@ require('render-markdown').setup({
703730
heading = {
704731
-- Turn on / off heading icon & background rendering
705732
enabled = true,
733+
-- Additional modes to render headings
734+
render_modes = false,
706735
-- Turn on / off any sign column related rendering
707736
sign = true,
708737
-- Determines how icons fill the available space:
@@ -789,6 +818,8 @@ require('render-markdown').setup({
789818
paragraph = {
790819
-- Turn on / off paragraph rendering
791820
enabled = true,
821+
-- Additional modes to render paragraphs
822+
render_modes = false,
792823
-- Amount of margin to add to the left of paragraphs
793824
-- If a floating point value < 1 is provided it is treated as a percentage of the available window space
794825
left_margin = 0,
@@ -813,6 +844,8 @@ require('render-markdown').setup({
813844
code = {
814845
-- Turn on / off code block & inline code rendering
815846
enabled = true,
847+
-- Additional modes to render code blocks
848+
render_modes = false,
816849
-- Turn on / off any sign column related rendering
817850
sign = true,
818851
-- Determines how code blocks & inline code are rendered:
@@ -887,6 +920,8 @@ require('render-markdown').setup({
887920
dash = {
888921
-- Turn on / off thematic break rendering
889922
enabled = true,
923+
-- Additional modes to render dash
924+
render_modes = false,
890925
-- Replaces '---'|'***'|'___'|'* * *' of 'thematic_break'
891926
-- The icon gets repeated across the window's width
892927
icon = '',
@@ -919,6 +954,8 @@ require('render-markdown').setup({
919954
bullet = {
920955
-- Turn on / off list bullet rendering
921956
enabled = true,
957+
-- Additional modes to render list bullets
958+
render_modes = false,
922959
-- Replaces '-'|'+'|'*' of 'list_item'
923960
-- How deeply nested the list is determines the 'level', how far down at that level determines the 'index'
924961
-- If a function is provided both of these values are passed in using 1 based indexing
@@ -963,6 +1000,8 @@ require('render-markdown').setup({
9631000
checkbox = {
9641001
-- Turn on / off checkbox state rendering
9651002
enabled = true,
1003+
-- Additional modes to render checkboxes
1004+
render_modes = false,
9661005
-- Determines how icons fill the available space:
9671006
-- inline: underlying text is concealed resulting in a left aligned icon
9681007
-- overlay: result is left padded with spaces to hide any additional text
@@ -1013,6 +1052,8 @@ require('render-markdown').setup({
10131052
quote = {
10141053
-- Turn on / off block quote & callout rendering
10151054
enabled = true,
1055+
-- Additional modes to render quotes
1056+
render_modes = false,
10161057
-- Replaces '>' of 'block_quote'
10171058
icon = '',
10181059
-- Whether to repeat icon on wrapped lines. Requires neovim >= 0.10. This will obscure text if
@@ -1042,6 +1083,8 @@ require('render-markdown').setup({
10421083
pipe_table = {
10431084
-- Turn on / off pipe table rendering
10441085
enabled = true,
1086+
-- Additional modes to render pipe tables
1087+
render_modes = false,
10451088
-- Pre configured settings largely for setting table border easier
10461089
-- heavy: use thicker border characters
10471090
-- double: use double line border characters
@@ -1151,6 +1194,8 @@ require('render-markdown').setup({
11511194
link = {
11521195
-- Turn on / off inline link icon rendering
11531196
enabled = true,
1197+
-- Additional modes to render links
1198+
render_modes = false,
11541199
-- How to handle footnote links, start with a '^'
11551200
footnote = {
11561201
-- Replace value with superscript equivalent
@@ -1229,6 +1274,8 @@ require('render-markdown').setup({
12291274
indent = {
12301275
-- Turn on / off org-indent-mode
12311276
enabled = false,
1277+
-- Additional modes to render indents
1278+
render_modes = false,
12321279
-- Amount of additional padding added for each heading level
12331280
per_level = 2,
12341281
-- Heading levels <= this value will not be indented

0 commit comments

Comments
 (0)