Skip to content

Commit d6a82d7

Browse files
feat: support highlighting when nested in double equals
## Details Adds support for Obsidian style inline highlights which are sections of text that are surrounded by "==". When these are found the equals signs on both ends are concealed and the inner portion of text is highlighted using the configured highlight group. By default links to the same value as inline code. Configuration is placed under `inline_highlight`. The rendering logic is all contained in the inline_highlight renderer module. Also includes a large refactor to how concealed text and inline offsets are handled: - Store ranges with a width for the concealed sections, that way any nodes that overlap simply add the width rather than doing a per character computation. - Allow concealing added by this plugin to be treated in the exact same way as concealing from highlights, including rules for different levels. - Update context with offsets and concealed ranges based on the marks being added rather than ad hoc logic while adding the marks. A mark with conceal is treated as a conceal highlight. A mark with inline virtual text is treated as an offset. Having both also works, some values will end up cancelling out as a result. This should capture any new features automatically, like the one for inline highlights, nice! - Move all the conceal handling into its own module which will be pulled from the context where it's needed. Other small changes: - Add a convenience `add_over` method to list module which populates start & end, row & col, from a provided node. Useful in many instances where we add some style directly inline with or over an existing node. - Remove `hidden` method from context and instead use `width == 0`. - Use `width` when computing amount of space for the heading icon - Remove custom handler test which had a version of this logic. - Update table spec to test behavior of inline highlighting - Update default table format level for luassert.
1 parent 430a671 commit d6a82d7

29 files changed

+584
-513
lines changed

README.md

+43-34
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,14 @@ require('render-markdown').setup({
532532
-- Applies to background of sign text
533533
highlight = 'RenderMarkdownSign',
534534
},
535+
-- Mimics Obsidian inline highlights when content is surrounded by double equals
536+
-- The equals on both ends are concealed and the inner content is highlighted
537+
inline_highlight = {
538+
-- Turn on / off inline highlight rendering
539+
enabled = true,
540+
-- Applies to background of surrounded text
541+
highlight = 'RenderMarkdownInlineHighlight',
542+
},
535543
-- Mimic org-indent-mode behavior by indenting everything under a heading based on the
536544
-- level of the heading. Indenting starts from level 2 headings onward.
537545
indent = {
@@ -1117,40 +1125,41 @@ require('render-markdown').setup({
11171125

11181126
The table below shows all the highlight groups with their default link
11191127

1120-
| Highlight Group | Default Group | Description |
1121-
| ------------------------ | ---------------------------------- | ------------------------- |
1122-
| RenderMarkdownH1 | @markup.heading.1.markdown | H1 icons |
1123-
| RenderMarkdownH2 | @markup.heading.2.markdown | H2 icons |
1124-
| RenderMarkdownH3 | @markup.heading.3.markdown | H3 icons |
1125-
| RenderMarkdownH4 | @markup.heading.4.markdown | H4 icons |
1126-
| RenderMarkdownH5 | @markup.heading.5.markdown | H5 icons |
1127-
| RenderMarkdownH6 | @markup.heading.6.markdown | H6 icons |
1128-
| RenderMarkdownH1Bg | DiffAdd | H1 background line |
1129-
| RenderMarkdownH2Bg | DiffChange | H2 background line |
1130-
| RenderMarkdownH3Bg | DiffDelete | H3 background line |
1131-
| RenderMarkdownH4Bg | DiffDelete | H4 background line |
1132-
| RenderMarkdownH5Bg | DiffDelete | H5 background line |
1133-
| RenderMarkdownH6Bg | DiffDelete | H6 background line |
1134-
| RenderMarkdownCode | ColorColumn | Code block background |
1135-
| RenderMarkdownCodeInline | RenderMarkdownCode | Inline code background |
1136-
| RenderMarkdownBullet | Normal | List item bullet points |
1137-
| RenderMarkdownQuote | @markup.quote | Block quote marker |
1138-
| RenderMarkdownDash | LineNr | Thematic break line |
1139-
| RenderMarkdownSign | SignColumn | Sign column background |
1140-
| RenderMarkdownMath | @markup.math | LaTeX lines |
1141-
| RenderMarkdownLink | @markup.link.label.markdown_inline | Image & hyperlink icons |
1142-
| RenderMarkdownWikiLink | RenderMarkdownLink | WikiLink icon & text |
1143-
| RenderMarkdownUnchecked | @markup.list.unchecked | Unchecked checkbox |
1144-
| RenderMarkdownChecked | @markup.list.checked | Checked checkbox |
1145-
| RenderMarkdownTodo | @markup.raw | Todo custom checkbox |
1146-
| RenderMarkdownTableHead | @markup.heading | Pipe table heading rows |
1147-
| RenderMarkdownTableRow | Normal | Pipe table body rows |
1148-
| RenderMarkdownTableFill | Conceal | Pipe table inline padding |
1149-
| RenderMarkdownSuccess | DiagnosticOk | Success related callouts |
1150-
| RenderMarkdownInfo | DiagnosticInfo | Info related callouts |
1151-
| RenderMarkdownHint | DiagnosticHint | Hint related callouts |
1152-
| RenderMarkdownWarn | DiagnosticWarn | Warning related callouts |
1153-
| RenderMarkdownError | DiagnosticError | Error related callouts |
1128+
| Highlight Group | Default Group | Description |
1129+
| ----------------------------- | ---------------------------------- | -------------------------- |
1130+
| RenderMarkdownH1 | @markup.heading.1.markdown | H1 icons |
1131+
| RenderMarkdownH2 | @markup.heading.2.markdown | H2 icons |
1132+
| RenderMarkdownH3 | @markup.heading.3.markdown | H3 icons |
1133+
| RenderMarkdownH4 | @markup.heading.4.markdown | H4 icons |
1134+
| RenderMarkdownH5 | @markup.heading.5.markdown | H5 icons |
1135+
| RenderMarkdownH6 | @markup.heading.6.markdown | H6 icons |
1136+
| RenderMarkdownH1Bg | DiffAdd | H1 background line |
1137+
| RenderMarkdownH2Bg | DiffChange | H2 background line |
1138+
| RenderMarkdownH3Bg | DiffDelete | H3 background line |
1139+
| RenderMarkdownH4Bg | DiffDelete | H4 background line |
1140+
| RenderMarkdownH5Bg | DiffDelete | H5 background line |
1141+
| RenderMarkdownH6Bg | DiffDelete | H6 background line |
1142+
| RenderMarkdownCode | ColorColumn | Code block background |
1143+
| RenderMarkdownCodeInline | RenderMarkdownCode | Inline code background |
1144+
| RenderMarkdownInlineHighlight | RenderMarkdownCodeInline | Inline highlights contents |
1145+
| RenderMarkdownBullet | Normal | List item bullet points |
1146+
| RenderMarkdownQuote | @markup.quote | Block quote marker |
1147+
| RenderMarkdownDash | LineNr | Thematic break line |
1148+
| RenderMarkdownSign | SignColumn | Sign column background |
1149+
| RenderMarkdownMath | @markup.math | LaTeX lines |
1150+
| RenderMarkdownLink | @markup.link.label.markdown_inline | Image & hyperlink icons |
1151+
| RenderMarkdownWikiLink | RenderMarkdownLink | WikiLink icon & text |
1152+
| RenderMarkdownUnchecked | @markup.list.unchecked | Unchecked checkbox |
1153+
| RenderMarkdownChecked | @markup.list.checked | Checked checkbox |
1154+
| RenderMarkdownTodo | @markup.raw | Todo custom checkbox |
1155+
| RenderMarkdownTableHead | @markup.heading | Pipe table heading rows |
1156+
| RenderMarkdownTableRow | Normal | Pipe table body rows |
1157+
| RenderMarkdownTableFill | Conceal | Pipe table inline padding |
1158+
| RenderMarkdownSuccess | DiagnosticOk | Success related callouts |
1159+
| RenderMarkdownInfo | DiagnosticInfo | Info related callouts |
1160+
| RenderMarkdownHint | DiagnosticHint | Hint related callouts |
1161+
| RenderMarkdownWarn | DiagnosticWarn | Warning related callouts |
1162+
| RenderMarkdownError | DiagnosticError | Error related callouts |
11541163

11551164
# Info
11561165

doc/render-markdown.txt

+60-46
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For 0.10.0 Last change: 2024 November 18
1+
*render-markdown.txt* For 0.10.0 Last change: 2024 November 20
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*
@@ -579,6 +579,14 @@ Default Configuration ~
579579
-- Applies to background of sign text
580580
highlight = 'RenderMarkdownSign',
581581
},
582+
-- Mimics Obsidian inline highlights when content is surrounded by double equals
583+
-- The equals on both ends are concealed and the inner content is highlighted
584+
inline_highlight = {
585+
-- Turn on / off inline highlight rendering
586+
enabled = true,
587+
-- Applies to background of surrounded text
588+
highlight = 'RenderMarkdownInlineHighlight',
589+
},
582590
-- Mimic org-indent-mode behavior by indenting everything under a heading based on the
583591
-- level of the heading. Indenting starts from level 2 headings onward.
584592
indent = {
@@ -1140,82 +1148,88 @@ Indent Configuration ~
11401148

11411149
The table below shows all the highlight groups with their default link
11421150

1143-
-------------------------------------------------------------------------------------
1144-
Highlight Group Default Group Description
1145-
-------------------------- ------------------------------------ ---------------------
1146-
RenderMarkdownH1 @markup.heading.1.markdown H1 icons
1151+
-----------------------------------------------------------------------------------------
1152+
Highlight Group Default Group Description
1153+
------------------------------- ------------------------------------ --------------------
1154+
RenderMarkdownH1 @markup.heading.1.markdown H1 icons
1155+
1156+
RenderMarkdownH2 @markup.heading.2.markdown H2 icons
11471157

1148-
RenderMarkdownH2 @markup.heading.2.markdown H2 icons
1158+
RenderMarkdownH3 @markup.heading.3.markdown H3 icons
11491159

1150-
RenderMarkdownH3 @markup.heading.3.markdown H3 icons
1160+
RenderMarkdownH4 @markup.heading.4.markdown H4 icons
11511161

1152-
RenderMarkdownH4 @markup.heading.4.markdown H4 icons
1162+
RenderMarkdownH5 @markup.heading.5.markdown H5 icons
11531163

1154-
RenderMarkdownH5 @markup.heading.5.markdown H5 icons
1164+
RenderMarkdownH6 @markup.heading.6.markdown H6 icons
11551165

1156-
RenderMarkdownH6 @markup.heading.6.markdown H6 icons
1166+
RenderMarkdownH1Bg DiffAdd H1 background line
11571167

1158-
RenderMarkdownH1Bg DiffAdd H1 background line
1168+
RenderMarkdownH2Bg DiffChange H2 background line
11591169

1160-
RenderMarkdownH2Bg DiffChange H2 background line
1170+
RenderMarkdownH3Bg DiffDelete H3 background line
11611171

1162-
RenderMarkdownH3Bg DiffDelete H3 background line
1172+
RenderMarkdownH4Bg DiffDelete H4 background line
11631173

1164-
RenderMarkdownH4Bg DiffDelete H4 background line
1174+
RenderMarkdownH5Bg DiffDelete H5 background line
11651175

1166-
RenderMarkdownH5Bg DiffDelete H5 background line
1176+
RenderMarkdownH6Bg DiffDelete H6 background line
11671177

1168-
RenderMarkdownH6Bg DiffDelete H6 background line
1178+
RenderMarkdownCode ColorColumn Code block
1179+
background
11691180

1170-
RenderMarkdownCode ColorColumn Code block background
1181+
RenderMarkdownCodeInline RenderMarkdownCode Inline code
1182+
background
11711183

1172-
RenderMarkdownCodeInline RenderMarkdownCode Inline code
1173-
background
1184+
RenderMarkdownInlineHighlight RenderMarkdownCodeInline Inline highlights
1185+
contents
11741186

1175-
RenderMarkdownBullet Normal List item bullet
1176-
points
1187+
RenderMarkdownBullet Normal List item bullet
1188+
points
11771189

1178-
RenderMarkdownQuote @markup.quote Block quote marker
1190+
RenderMarkdownQuote @markup.quote Block quote marker
11791191

1180-
RenderMarkdownDash LineNr Thematic break line
1192+
RenderMarkdownDash LineNr Thematic break line
11811193

1182-
RenderMarkdownSign SignColumn Sign column
1183-
background
1194+
RenderMarkdownSign SignColumn Sign column
1195+
background
11841196

1185-
RenderMarkdownMath @markup.math LaTeX lines
1197+
RenderMarkdownMath @markup.math LaTeX lines
11861198

1187-
RenderMarkdownLink @markup.link.label.markdown_inline Image & hyperlink
1188-
icons
1199+
RenderMarkdownLink @markup.link.label.markdown_inline Image & hyperlink
1200+
icons
11891201

1190-
RenderMarkdownWikiLink RenderMarkdownLink WikiLink icon & text
1202+
RenderMarkdownWikiLink RenderMarkdownLink WikiLink icon & text
11911203

1192-
RenderMarkdownUnchecked @markup.list.unchecked Unchecked checkbox
1204+
RenderMarkdownUnchecked @markup.list.unchecked Unchecked checkbox
11931205

1194-
RenderMarkdownChecked @markup.list.checked Checked checkbox
1206+
RenderMarkdownChecked @markup.list.checked Checked checkbox
11951207

1196-
RenderMarkdownTodo @markup.raw Todo custom checkbox
1208+
RenderMarkdownTodo @markup.raw Todo custom checkbox
11971209

1198-
RenderMarkdownTableHead @markup.heading Pipe table heading
1199-
rows
1210+
RenderMarkdownTableHead @markup.heading Pipe table heading
1211+
rows
12001212

1201-
RenderMarkdownTableRow Normal Pipe table body rows
1213+
RenderMarkdownTableRow Normal Pipe table body rows
12021214

1203-
RenderMarkdownTableFill Conceal Pipe table inline
1204-
padding
1215+
RenderMarkdownTableFill Conceal Pipe table inline
1216+
padding
12051217

1206-
RenderMarkdownSuccess DiagnosticOk Success related
1207-
callouts
1218+
RenderMarkdownSuccess DiagnosticOk Success related
1219+
callouts
12081220

1209-
RenderMarkdownInfo DiagnosticInfo Info related callouts
1221+
RenderMarkdownInfo DiagnosticInfo Info related
1222+
callouts
12101223

1211-
RenderMarkdownHint DiagnosticHint Hint related callouts
1224+
RenderMarkdownHint DiagnosticHint Hint related
1225+
callouts
12121226

1213-
RenderMarkdownWarn DiagnosticWarn Warning related
1214-
callouts
1227+
RenderMarkdownWarn DiagnosticWarn Warning related
1228+
callouts
12151229

1216-
RenderMarkdownError DiagnosticError Error related
1217-
callouts
1218-
-------------------------------------------------------------------------------------
1230+
RenderMarkdownError DiagnosticError Error related
1231+
callouts
1232+
-----------------------------------------------------------------------------------------
12191233

12201234
==============================================================================
12211235
8. Info *render-markdown-info*

lua/render-markdown/colors.lua

+33-32
Original file line numberDiff line numberDiff line change
@@ -17,43 +17,44 @@ M.prefix = 'RenderMarkdown'
1717
---@type table<string, string>
1818
M.colors = {
1919
-- Headings
20-
H1 = '@markup.heading.1.markdown',
21-
H2 = '@markup.heading.2.markdown',
22-
H3 = '@markup.heading.3.markdown',
23-
H4 = '@markup.heading.4.markdown',
24-
H5 = '@markup.heading.5.markdown',
25-
H6 = '@markup.heading.6.markdown',
26-
H1Bg = 'DiffAdd',
27-
H2Bg = 'DiffChange',
28-
H3Bg = 'DiffDelete',
29-
H4Bg = 'DiffDelete',
30-
H5Bg = 'DiffDelete',
31-
H6Bg = 'DiffDelete',
20+
H1 = '@markup.heading.1.markdown',
21+
H2 = '@markup.heading.2.markdown',
22+
H3 = '@markup.heading.3.markdown',
23+
H4 = '@markup.heading.4.markdown',
24+
H5 = '@markup.heading.5.markdown',
25+
H6 = '@markup.heading.6.markdown',
26+
H1Bg = 'DiffAdd',
27+
H2Bg = 'DiffChange',
28+
H3Bg = 'DiffDelete',
29+
H4Bg = 'DiffDelete',
30+
H5Bg = 'DiffDelete',
31+
H6Bg = 'DiffDelete',
3232
-- General
33-
Code = 'ColorColumn',
34-
CodeInline = 'RenderMarkdownCode',
35-
Bullet = 'Normal',
36-
Quote = '@markup.quote',
37-
Dash = 'LineNr',
38-
Sign = 'SignColumn',
39-
Math = '@markup.math',
33+
Code = 'ColorColumn',
34+
CodeInline = 'RenderMarkdownCode',
35+
InlineHighlight = 'RenderMarkdownCodeInline',
36+
Bullet = 'Normal',
37+
Quote = '@markup.quote',
38+
Dash = 'LineNr',
39+
Sign = 'SignColumn',
40+
Math = '@markup.math',
4041
-- Links
41-
Link = '@markup.link.label.markdown_inline',
42-
WikiLink = 'RenderMarkdownLink',
42+
Link = '@markup.link.label.markdown_inline',
43+
WikiLink = 'RenderMarkdownLink',
4344
-- Checkboxes
44-
Unchecked = '@markup.list.unchecked',
45-
Checked = '@markup.list.checked',
46-
Todo = '@markup.raw',
45+
Unchecked = '@markup.list.unchecked',
46+
Checked = '@markup.list.checked',
47+
Todo = '@markup.raw',
4748
-- Pipe tables
48-
TableHead = '@markup.heading',
49-
TableRow = 'Normal',
50-
TableFill = 'Conceal',
49+
TableHead = '@markup.heading',
50+
TableRow = 'Normal',
51+
TableFill = 'Conceal',
5152
-- Callouts
52-
Success = 'DiagnosticOk',
53-
Info = 'DiagnosticInfo',
54-
Hint = 'DiagnosticHint',
55-
Warn = 'DiagnosticWarn',
56-
Error = 'DiagnosticError',
53+
Success = 'DiagnosticOk',
54+
Info = 'DiagnosticInfo',
55+
Hint = 'DiagnosticHint',
56+
Warn = 'DiagnosticWarn',
57+
Error = 'DiagnosticError',
5758
}
5859

5960
---Should only be called from plugin directory

0 commit comments

Comments
 (0)