Skip to content

Commit ca3d0da

Browse files
committed
Added :MDEPathToURL command
1 parent 5adc397 commit ca3d0da

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

doc/markdown_extras.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ filling it with he various keys.
202202
greater than 0.
203203
"fuzzy_search" Fuzzy or exact search in the links popup.
204204
Default: |true|.
205+
"path_to_url_register" Register used when running the |:MDEPathToURL|
206+
command.
207+
Default: 'p'.
205208
"hack_CR" Set to |false| for the standard behavior of <CR>.
206209
Default: |true|.
207210
"large_files_threshold" If you have large files linked to your document,
@@ -302,6 +305,12 @@ COMMANDS *markdown-extras-commands*
302305
`pandoc`. Its behavior can be further customized through
303306
the |g:markdown_extras_config| dictionary.
304307

308+
*:MDEPathToURL*
309+
:MDEPathToURL Convert the passed file name to a valid URL and store the
310+
result in a register. The default register is 'p' but that
311+
can be changed through the |g:markdown_extras_config|
312+
dictionary.
313+
305314
==============================================================================
306315
MAPPINGS *markdown-extras-mappings*
307316

plugin/markdown_extras.vim

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ If `:MDEIndices` is called without arguments, then the value of
5454
`g:markdown_extras_index` is used.
5555
Finally, such a command is now global.
5656

57+
58+
## :MDEPathToURL
59+
Convert the passed file name to a valid URL and store the result in a register.
60+
The default register is 'p' but that can be changed through the
61+
g:markdown_extras_config dictionary.
62+
63+
5764
Press <Esc> to close this popup.
5865
END
5966

@@ -145,6 +152,19 @@ if use_pandoc && !executable('pandoc')
145152
endif
146153
endif
147154

155+
# PathToURL
156+
def PathToURLReg(path: string)
157+
var path_to_url_register = 'p'
158+
if exists('g:markdown_extras_config') != 0
159+
&& has_key(g:markdown_extras_config, 'path_to_url_register')
160+
path_to_url_register = g:markdown_extras_config['path_to_url_register']
161+
endif
162+
163+
setreg(path_to_url_register, indices.PathToURL(fnamemodify(path, ':p')))
164+
echo $"URL stored in register '{path_to_url_register}'"
165+
enddef
166+
167+
command! -nargs=1 -complete=file MDEPathToURL PathToURLReg(<f-args>)
148168
command! -nargs=0 MDEReleaseNotes ShowReleaseNotes()
149169
command! -nargs=? MDEIndex indices.ShowIndex(<f-args>)
150170

0 commit comments

Comments
 (0)