Skip to content

Commit 1fea96a

Browse files
committed
Added lib/highlight
1 parent e216ee6 commit 1fea96a

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

after/ftplugin/markdown.vim

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import autoload "../../lib/funcs.vim"
44
import autoload "../../lib/preview.vim"
55
import autoload "../../lib/links.vim"
66
import autoload '../../lib/utils.vim'
7+
import autoload '../../lib/highlight.vim'
78
import autoload '../../lib/constants.vim'
89

910

@@ -61,8 +62,8 @@ if use_pandoc && executable('pandoc')
6162

6263
compiler pandoc
6364

65+
# TODO: make it to take additional arguments
6466
def Make(format: string = 'html')
65-
#
6667

6768
var output_file = $'{expand('%:p:r')}.{format}'
6869
var cmd = execute($'make {format}')
@@ -178,6 +179,15 @@ if empty(maparg('<Plug>MarkdownCode'))
178179
\ TEXT_STYLES_DICT, TEXT_STYLES_DICT)<cr>g@
179180
endif
180181

182+
if empty(maparg('<Plug>MarkdownAddHighlight'))
183+
noremap <script> <buffer> <Plug>MarkdownAddHighlight
184+
\ <esc><ScriptCmd>highlight.AddProp()<cr>
185+
endif
186+
187+
if empty(maparg('<Plug>MarkdownClearHighlight'))
188+
noremap <script> <buffer> <Plug>MarkdownClearHighlight
189+
\ <esc><ScriptCmd>highlight.ClearProp()<cr>
190+
endif
181191
# ----------- TODO:TO BE REVIEWED ----------------------
182192

183193
def SetCodeBlock(open_block: dict<string>,
@@ -255,4 +265,12 @@ if use_default_mappings
255265
if !hasmapto('<Plug>MarkdownReferencePreview')
256266
nnoremap <buffer> <silent> K <Plug>MarkdownReferencePreview
257267
endif
268+
269+
# ---------- Highlight --------------------------
270+
if !hasmapto('<Plug>MarkdownAddHighlight')
271+
xnoremap <leader>ha <Plug>MarkdownAddHighlight
272+
endif
273+
if !hasmapto('<Plug>MarkdownClearHighlight')
274+
xnoremap <leader>hd <Plug>MarkdownClearHighlight
275+
endif
258276
endif

doc/tags

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
ReplicaContents markdown_extras.txt /*ReplicaContents*
2-
ReplicaIntroduction markdown_extras.txt /*ReplicaIntroduction*
1+
g:markdown_extras_config markdown_extras.txt /*g:markdown_extras_config*
32
markdown-extras markdown_extras.txt /*markdown-extras*
3+
markdown-extras-configuration markdown_extras.txt /*markdown-extras-configuration*
4+
markdown-extras-contents markdown_extras.txt /*markdown-extras-contents*
5+
markdown-extras-introduction markdown_extras.txt /*markdown-extras-introduction*
6+
markdown-extras-requirements markdown_extras.txt /*markdown-extras-requirements*

lib/highlight.vim

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
vim9script
2+
3+
# TODO: use opfunc
4+
# TODO: use search mechanism
5+
var prop_id = 0
6+
var hi_group = 'IncSearch'
7+
8+
if exists('g:markdown_extras_config') != 0
9+
&& has_key(g:markdown_extras_config, 'hi_group')
10+
&& g:markdown_extras_config['']
11+
hi_group = g:markdown_extras_config['hi_group']
12+
endif
13+
14+
if empty(prop_type_get('markdown_extras_highlight'))
15+
prop_type_add('markdown_extras_highlight', {highlight: hi_group})
16+
endif
17+
18+
export def AddProp()
19+
var lA = getpos("'<")[1]
20+
var cA = getpos("'<")[2]
21+
var lB = getpos("'>")[1]
22+
var cB = getpos("'>")[2]
23+
24+
prop_add(lA, cA, {id: prop_id, type: 'markdown_extras_highlight',
25+
end_lnum: lB, end_col: cB})
26+
prop_id += 1
27+
enddef
28+
29+
export def ClearProp()
30+
var lA = getpos("'<")[1]
31+
var lB = getpos("'>")[1]
32+
33+
prop_clear(lA, lB)
34+
enddef

0 commit comments

Comments
 (0)