Skip to content

Commit d19cc85

Browse files
habamaxvim-scripts
authored andcommitted
Version 2.0.1.stu
* Follow (i.e. open target of) markdown reference-style links. * Bug fixes.
1 parent d5a6d09 commit d19cc85

File tree

9 files changed

+422
-99
lines changed

9 files changed

+422
-99
lines changed

autoload/vimwiki/base.vim

Lines changed: 123 additions & 52 deletions
Large diffs are not rendered by default.

autoload/vimwiki/diary.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,12 @@ function! vimwiki#diary#make_note(wnum, ...) "{{{
237237
call vimwiki#base#validate_wiki_options(idx)
238238
call vimwiki#base#mkdir(VimwikiGet('path', idx).VimwikiGet('diary_rel_path', idx))
239239

240-
if a:0
240+
if a:0 && a:1 == 1
241241
let cmd = 'tabedit'
242242
else
243243
let cmd = 'edit'
244244
endif
245-
if len(a:0)>1
245+
if a:0>1
246246
let link = 'diary:'.a:2
247247
else
248248
let link = 'diary:'.s:diary_date_link(idx)

autoload/vimwiki/html.vim

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,13 @@ function! s:tag_wikiincl(value) "{{{
422422
if g:vimwiki_debug > 1
423423
echom '{{idx='.idx.', scheme='.scheme.', path='.path.', subdir='.subdir.', lnk='.lnk.', ext='.ext.'}}'
424424
endif
425+
426+
" Issue 343: Image transclusions: schemeless links have .html appended.
427+
" If link is schemeless pass it as it is
428+
if scheme == ''
429+
let url = lnk
430+
endif
431+
425432
let url = escape(url, '#')
426433
let line = vimwiki#html#linkify_image(url, descr, verbatim_str)
427434
return line

autoload/vimwiki/markdown_base.vim

Lines changed: 198 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,190 @@
11
" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79
22
" Vimwiki autoload plugin file
33
" Desc: Link functions for markdown syntax
4-
" Author: Maxim Kim <habamax@gmail.com>
4+
" Author: Stuart Andrews <stu.andrews@gmail.com> (.. i.e. don't blame Maxim!)
55
" Home: http://code.google.com/p/vimwiki/
66

77

8+
" MISC helper functions {{{
9+
10+
" vimwiki#markdown_base#reset_mkd_refs
11+
function! vimwiki#markdown_base#reset_mkd_refs() "{{{
12+
call VimwikiClear('markdown_refs')
13+
endfunction "}}}
14+
15+
" vimwiki#markdown_base#scan_reflinks
16+
function! vimwiki#markdown_base#scan_reflinks() " {{{
17+
let mkd_refs = {}
18+
" construct list of references using vimgrep
19+
try
20+
execute 'vimgrep #'.g:vimwiki_rxMkdRef.'#j %'
21+
catch /^Vim\%((\a\+)\)\=:E480/ " No Match
22+
"Ignore it, and move on to the next file
23+
endtry
24+
"
25+
for d in getqflist()
26+
let matchline = join(getline(d.lnum, min([d.lnum+1, line('$')])), ' ')
27+
let descr = matchstr(matchline, g:vimwiki_rxMkdRefMatchDescr)
28+
let url = matchstr(matchline, g:vimwiki_rxMkdRefMatchUrl)
29+
if descr != '' && url != ''
30+
let mkd_refs[descr] = url
31+
endif
32+
endfor
33+
call VimwikiSet('markdown_refs', mkd_refs)
34+
return mkd_refs
35+
endfunction "}}}
36+
37+
38+
" vimwiki#markdown_base#get_reflinks
39+
function! vimwiki#markdown_base#get_reflinks() " {{{
40+
let done = 1
41+
try
42+
let mkd_refs = VimwikiGet('markdown_refs')
43+
catch
44+
" work-around hack
45+
let done = 0
46+
" ... the following command does not work inside catch block !?
47+
" > let mkd_refs = vimwiki#markdown_base#scan_reflinks()
48+
endtry
49+
if !done
50+
let mkd_refs = vimwiki#markdown_base#scan_reflinks()
51+
endif
52+
return mkd_refs
53+
endfunction "}}}
54+
55+
" vimwiki#markdown_base#open_reflink
56+
" try markdown reference links
57+
function! vimwiki#markdown_base#open_reflink(link) " {{{
58+
" echom "vimwiki#markdown_base#open_reflink"
59+
let link = a:link
60+
let mkd_refs = vimwiki#markdown_base#get_reflinks()
61+
if has_key(mkd_refs, link)
62+
let url = mkd_refs[link]
63+
call vimwiki#base#system_open_link(url)
64+
return 1
65+
else
66+
return 0
67+
endif
68+
endfunction " }}}
69+
70+
" s:normalize_path
71+
" s:path_html
72+
" vimwiki#base#apply_wiki_options
73+
" vimwiki#base#read_wiki_options
74+
" vimwiki#base#validate_wiki_options
75+
" vimwiki#base#setup_buffer_state
76+
" vimwiki#base#cache_buffer_state
77+
" vimwiki#base#recall_buffer_state
78+
" vimwiki#base#print_wiki_state
79+
" vimwiki#base#mkdir
80+
" vimwiki#base#file_pattern
81+
" vimwiki#base#branched_pattern
82+
" vimwiki#base#subdir
83+
" vimwiki#base#current_subdir
84+
" vimwiki#base#invsubdir
85+
" vimwiki#base#resolve_scheme
86+
" vimwiki#base#system_open_link
87+
" vimwiki#base#open_link
88+
" vimwiki#base#generate_links
89+
" vimwiki#base#goto
90+
" vimwiki#base#backlinks
91+
" vimwiki#base#get_links
92+
" vimwiki#base#edit_file
93+
" vimwiki#base#search_word
94+
" vimwiki#base#matchstr_at_cursor
95+
" vimwiki#base#replacestr_at_cursor
96+
" s:print_wiki_list
97+
" s:update_wiki_link
98+
" s:update_wiki_links_dir
99+
" s:tail_name
100+
" s:update_wiki_links
101+
" s:get_wiki_buffers
102+
" s:open_wiki_buffer
103+
" vimwiki#base#nested_syntax
104+
" }}}
105+
106+
" WIKI link following functions {{{
107+
" vimwiki#base#find_next_link
108+
" vimwiki#base#find_prev_link
109+
110+
" vimwiki#base#follow_link
111+
function! vimwiki#markdown_base#follow_link(split, ...) "{{{ Parse link at cursor and pass
112+
" to VimwikiLinkHandler, or failing that, the default open_link handler
113+
" echom "markdown_base#follow_link"
114+
115+
if 0
116+
" Syntax-specific links
117+
" XXX: @Stuart: do we still need it?
118+
" XXX: @Maxim: most likely! I am still working on a seemless way to
119+
" integrate regexp's without complicating syntax/vimwiki.vim
120+
else
121+
if a:split == "split"
122+
let cmd = ":split "
123+
elseif a:split == "vsplit"
124+
let cmd = ":vsplit "
125+
elseif a:split == "tabnew"
126+
let cmd = ":tabnew "
127+
else
128+
let cmd = ":e "
129+
endif
130+
131+
" try WikiLink
132+
let lnk = matchstr(vimwiki#base#matchstr_at_cursor(g:vimwiki_rxWikiLink),
133+
\ g:vimwiki_rxWikiLinkMatchUrl)
134+
" try WikiIncl
135+
if lnk == ""
136+
let lnk = matchstr(vimwiki#base#matchstr_at_cursor(g:vimwiki_rxWikiIncl),
137+
\ g:vimwiki_rxWikiInclMatchUrl)
138+
endif
139+
" try Weblink
140+
if lnk == ""
141+
let lnk = matchstr(vimwiki#base#matchstr_at_cursor(g:vimwiki_rxWeblink),
142+
\ g:vimwiki_rxWeblinkMatchUrl)
143+
endif
144+
145+
if lnk != ""
146+
if !VimwikiLinkHandler(lnk)
147+
if !vimwiki#markdown_base#open_reflink(lnk)
148+
call vimwiki#base#open_link(cmd, lnk)
149+
endif
150+
endif
151+
return
152+
endif
153+
154+
if a:0 > 0
155+
execute "normal! ".a:1
156+
else
157+
call vimwiki#base#normalize_link(0)
158+
endif
159+
endif
160+
161+
endfunction " }}}
162+
163+
" vimwiki#base#go_back_link
164+
" vimwiki#base#goto_index
165+
" vimwiki#base#delete_link
166+
" vimwiki#base#rename_link
167+
" vimwiki#base#ui_select
168+
169+
" TEXT OBJECTS functions {{{
170+
" vimwiki#base#TO_header
171+
" vimwiki#base#TO_table_cell
172+
" vimwiki#base#TO_table_col
173+
" }}}
174+
175+
" HEADER functions {{{
176+
" vimwiki#base#AddHeaderLevel
177+
" vimwiki#base#RemoveHeaderLevel
178+
"}}}
179+
180+
" LINK functions {{{
181+
" vimwiki#base#apply_template
182+
183+
" s:clean_url
184+
" vimwiki#base#normalize_link_helper
185+
" vimwiki#base#normalize_imagelink_helper
186+
187+
" s:normalize_link_syntax_n
8188
function! s:normalize_link_syntax_n() " {{{
9189
let lnum = line('.')
10190

@@ -74,6 +254,7 @@ function! s:normalize_link_syntax_n() " {{{
74254

75255
endfunction " }}}
76256

257+
" s:normalize_link_syntax_v
77258
function! s:normalize_link_syntax_v() " {{{
78259
let lnum = line('.')
79260
let sel_save = &selection
@@ -99,13 +280,23 @@ function! s:normalize_link_syntax_v() " {{{
99280

100281
endfunction " }}}
101282

102-
" normalize_link
283+
" vimwiki#base#normalize_link
103284
function! vimwiki#markdown_base#normalize_link(is_visual_mode) "{{{
104-
if !a:is_visual_mode
105-
call s:normalize_link_syntax_n()
106-
elseif visualmode() ==# 'v' && line("'<") == line("'>")
107-
" action undefined for 'line-wise' or 'multi-line' visual mode selections
108-
call s:normalize_link_syntax_v()
285+
if 0
286+
" Syntax-specific links
287+
else
288+
if !a:is_visual_mode
289+
call s:normalize_link_syntax_n()
290+
elseif visualmode() ==# 'v' && line("'<") == line("'>")
291+
" action undefined for 'line-wise' or 'multi-line' visual mode selections
292+
call s:normalize_link_syntax_v()
293+
endif
109294
endif
110295
endfunction "}}}
111296

297+
" }}}
298+
299+
" -------------------------------------------------------------------------
300+
" Load syntax-specific Wiki functionality
301+
" -------------------------------------------------------------------------
302+

doc/vimwiki.txt

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
|___| |___| |_| |_||__| |__||___| |___| |_||___| ~
1010

1111

12-
Version: 2.0 'stu'
12+
Version: 2.0.1 'stu'
1313

1414
==============================================================================
1515
CONTENTS *vimwiki-contents*
@@ -610,10 +610,10 @@ Markdown Links~
610610
These links are only available for Markdown syntax. See
611611
http://daringfireball.net/projects/markdown/syntax#link.
612612

613-
Inline links: >
613+
Inline link: >
614614
[Looks like this](URL)
615615
616-
Image links: >
616+
Image link: >
617617
![Looks like this](URL)
618618
619619
The URL can be anything recognized by vimwiki as a raw URL.
@@ -623,10 +623,26 @@ Reference-style links: >
623623
a) [Link Name][Id]
624624
b) [Id][], using the "implicit link name" shortcut
625625
626-
Vimwiki treats reference style links just like default "Wikilinks". In the
627-
current implementation: the Id field must be a valid wiki page name,
628-
reference style links must always include *two* consecutive pairs of
629-
[-brackets, and entries can not use "[" or "]".
626+
Reference style links must always include *two* consecutive pairs of
627+
[-brackets, and field entries can not use "[" or "]".
628+
629+
630+
NOTE: (in Vimwiki's current implementation) Reference-style links are a hybrid
631+
of Vimwiki's default "Wikilink" and the tradition reference-style link.
632+
633+
If the Id is defined elsewhere in the source, as per the Markdown standard: >
634+
[Id]: URL
635+
636+
then the URL is opened with the system default handler. Otherwise, Vimwiki
637+
treats the reference-sytle link as a Wikilink, interpreting the Id field as a
638+
wiki page name.
639+
640+
Highlighting of existing links when |vimwiki-option-maxhi| is activated
641+
identifies links whose Id field is not defined, either as a reference-link or
642+
as a wiki page.
643+
644+
To scan the page for new or changed definitions for reference-links, simply
645+
re-open the page ":e<CR>".
630646

631647

632648
------------------------------------------------------------------------------
@@ -1193,29 +1209,29 @@ Use the :VimwikiTable command to create a default table with 5 columns and 2
11931209
rows: >
11941210
11951211
| | | | | |
1196-
|---+---+---+---+---|
1212+
|---|---|---|---|---|
11971213
| | | | | |
11981214
<
11991215

12001216
Tables are auto-formattable. Let's add some text into first cell: >
12011217
12021218
| First Name | | | | |
1203-
|---+---+---+---+---|
1219+
|---|---|---|---|---|
12041220
| | | | | |
12051221
<
12061222

12071223
Whenever you press <TAB>, <CR> or leave Insert mode, the table is formatted: >
12081224
12091225
| First Name | | | | |
1210-
|------------+---+---+---+---|
1226+
|------------|---|---|---|---|
12111227
| | | | | |
12121228
<
12131229

12141230
You can easily create nice-looking text tables, just press <TAB> and enter new
12151231
values: >
12161232
12171233
| First Name | Last Name | Age | City | e-mail |
1218-
|------------+------------+-----+----------+----------------------|
1234+
|------------|------------|-----|----------|----------------------|
12191235
| Vladislav | Pokrishkin | 31 | Moscow | vlad_pok@smail.com |
12201236
| James | Esfandiary | 27 | Istanbul | esfandiary@tmail.com |
12211237
<
@@ -2170,10 +2186,16 @@ Vim plugins: http://www.vim.org/scripts/script.php?script_id=2226
21702186
==============================================================================
21712187
14. Changelog *vimwiki-changelog*
21722188

2189+
2.0.1 'stu'~
2190+
2191+
* Follow (i.e. open target of) markdown reference-style links.
2192+
* Bug fixes.
2193+
2194+
21732195
2.0 'stu'~
21742196

21752197
This release is partly incompatible with previous.
2176-
2198+
*
21772199
Summary ~
21782200

21792201
* Quick page-link creation.

0 commit comments

Comments
 (0)