Skip to content

Commit

Permalink
Version 2.0.1.stu
Browse files Browse the repository at this point in the history
  * Follow (i.e. open target of) markdown reference-style links.
  * Bug fixes.
  • Loading branch information
habamax authored and vim-scripts committed Aug 8, 2012
1 parent d5a6d09 commit d19cc85
Show file tree
Hide file tree
Showing 9 changed files with 422 additions and 99 deletions.
175 changes: 123 additions & 52 deletions autoload/vimwiki/base.vim

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions autoload/vimwiki/diary.vim
Expand Up @@ -237,12 +237,12 @@ function! vimwiki#diary#make_note(wnum, ...) "{{{
call vimwiki#base#validate_wiki_options(idx) call vimwiki#base#validate_wiki_options(idx)
call vimwiki#base#mkdir(VimwikiGet('path', idx).VimwikiGet('diary_rel_path', idx)) call vimwiki#base#mkdir(VimwikiGet('path', idx).VimwikiGet('diary_rel_path', idx))


if a:0 if a:0 && a:1 == 1
let cmd = 'tabedit' let cmd = 'tabedit'
else else
let cmd = 'edit' let cmd = 'edit'
endif endif
if len(a:0)>1 if a:0>1
let link = 'diary:'.a:2 let link = 'diary:'.a:2
else else
let link = 'diary:'.s:diary_date_link(idx) let link = 'diary:'.s:diary_date_link(idx)
Expand Down
7 changes: 7 additions & 0 deletions autoload/vimwiki/html.vim
Expand Up @@ -422,6 +422,13 @@ function! s:tag_wikiincl(value) "{{{
if g:vimwiki_debug > 1 if g:vimwiki_debug > 1
echom '{{idx='.idx.', scheme='.scheme.', path='.path.', subdir='.subdir.', lnk='.lnk.', ext='.ext.'}}' echom '{{idx='.idx.', scheme='.scheme.', path='.path.', subdir='.subdir.', lnk='.lnk.', ext='.ext.'}}'
endif endif

" Issue 343: Image transclusions: schemeless links have .html appended.
" If link is schemeless pass it as it is
if scheme == ''
let url = lnk
endif

let url = escape(url, '#') let url = escape(url, '#')
let line = vimwiki#html#linkify_image(url, descr, verbatim_str) let line = vimwiki#html#linkify_image(url, descr, verbatim_str)
return line return line
Expand Down
205 changes: 198 additions & 7 deletions autoload/vimwiki/markdown_base.vim
@@ -1,10 +1,190 @@
" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79 " vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79
" Vimwiki autoload plugin file " Vimwiki autoload plugin file
" Desc: Link functions for markdown syntax " Desc: Link functions for markdown syntax
" Author: Maxim Kim <habamax@gmail.com> " Author: Stuart Andrews <stu.andrews@gmail.com> (.. i.e. don't blame Maxim!)
" Home: http://code.google.com/p/vimwiki/ " Home: http://code.google.com/p/vimwiki/




" MISC helper functions {{{

" vimwiki#markdown_base#reset_mkd_refs
function! vimwiki#markdown_base#reset_mkd_refs() "{{{
call VimwikiClear('markdown_refs')
endfunction "}}}

" vimwiki#markdown_base#scan_reflinks
function! vimwiki#markdown_base#scan_reflinks() " {{{
let mkd_refs = {}
" construct list of references using vimgrep
try
execute 'vimgrep #'.g:vimwiki_rxMkdRef.'#j %'
catch /^Vim\%((\a\+)\)\=:E480/ " No Match
"Ignore it, and move on to the next file
endtry
"
for d in getqflist()
let matchline = join(getline(d.lnum, min([d.lnum+1, line('$')])), ' ')
let descr = matchstr(matchline, g:vimwiki_rxMkdRefMatchDescr)
let url = matchstr(matchline, g:vimwiki_rxMkdRefMatchUrl)
if descr != '' && url != ''
let mkd_refs[descr] = url
endif
endfor
call VimwikiSet('markdown_refs', mkd_refs)
return mkd_refs
endfunction "}}}


" vimwiki#markdown_base#get_reflinks
function! vimwiki#markdown_base#get_reflinks() " {{{
let done = 1
try
let mkd_refs = VimwikiGet('markdown_refs')
catch
" work-around hack
let done = 0
" ... the following command does not work inside catch block !?
" > let mkd_refs = vimwiki#markdown_base#scan_reflinks()
endtry
if !done
let mkd_refs = vimwiki#markdown_base#scan_reflinks()
endif
return mkd_refs
endfunction "}}}

" vimwiki#markdown_base#open_reflink
" try markdown reference links
function! vimwiki#markdown_base#open_reflink(link) " {{{
" echom "vimwiki#markdown_base#open_reflink"
let link = a:link
let mkd_refs = vimwiki#markdown_base#get_reflinks()
if has_key(mkd_refs, link)
let url = mkd_refs[link]
call vimwiki#base#system_open_link(url)
return 1
else
return 0
endif
endfunction " }}}

" s:normalize_path
" s:path_html
" vimwiki#base#apply_wiki_options
" vimwiki#base#read_wiki_options
" vimwiki#base#validate_wiki_options
" vimwiki#base#setup_buffer_state
" vimwiki#base#cache_buffer_state
" vimwiki#base#recall_buffer_state
" vimwiki#base#print_wiki_state
" vimwiki#base#mkdir
" vimwiki#base#file_pattern
" vimwiki#base#branched_pattern
" vimwiki#base#subdir
" vimwiki#base#current_subdir
" vimwiki#base#invsubdir
" vimwiki#base#resolve_scheme
" vimwiki#base#system_open_link
" vimwiki#base#open_link
" vimwiki#base#generate_links
" vimwiki#base#goto
" vimwiki#base#backlinks
" vimwiki#base#get_links
" vimwiki#base#edit_file
" vimwiki#base#search_word
" vimwiki#base#matchstr_at_cursor
" vimwiki#base#replacestr_at_cursor
" s:print_wiki_list
" s:update_wiki_link
" s:update_wiki_links_dir
" s:tail_name
" s:update_wiki_links
" s:get_wiki_buffers
" s:open_wiki_buffer
" vimwiki#base#nested_syntax
" }}}

" WIKI link following functions {{{
" vimwiki#base#find_next_link
" vimwiki#base#find_prev_link

" vimwiki#base#follow_link
function! vimwiki#markdown_base#follow_link(split, ...) "{{{ Parse link at cursor and pass
" to VimwikiLinkHandler, or failing that, the default open_link handler
" echom "markdown_base#follow_link"

if 0
" Syntax-specific links
" XXX: @Stuart: do we still need it?
" XXX: @Maxim: most likely! I am still working on a seemless way to
" integrate regexp's without complicating syntax/vimwiki.vim
else
if a:split == "split"
let cmd = ":split "
elseif a:split == "vsplit"
let cmd = ":vsplit "
elseif a:split == "tabnew"
let cmd = ":tabnew "
else
let cmd = ":e "
endif

" try WikiLink
let lnk = matchstr(vimwiki#base#matchstr_at_cursor(g:vimwiki_rxWikiLink),
\ g:vimwiki_rxWikiLinkMatchUrl)
" try WikiIncl
if lnk == ""
let lnk = matchstr(vimwiki#base#matchstr_at_cursor(g:vimwiki_rxWikiIncl),
\ g:vimwiki_rxWikiInclMatchUrl)
endif
" try Weblink
if lnk == ""
let lnk = matchstr(vimwiki#base#matchstr_at_cursor(g:vimwiki_rxWeblink),
\ g:vimwiki_rxWeblinkMatchUrl)
endif

if lnk != ""
if !VimwikiLinkHandler(lnk)
if !vimwiki#markdown_base#open_reflink(lnk)
call vimwiki#base#open_link(cmd, lnk)
endif
endif
return
endif

if a:0 > 0
execute "normal! ".a:1
else
call vimwiki#base#normalize_link(0)
endif
endif

endfunction " }}}

" vimwiki#base#go_back_link
" vimwiki#base#goto_index
" vimwiki#base#delete_link
" vimwiki#base#rename_link
" vimwiki#base#ui_select

" TEXT OBJECTS functions {{{
" vimwiki#base#TO_header
" vimwiki#base#TO_table_cell
" vimwiki#base#TO_table_col
" }}}

" HEADER functions {{{
" vimwiki#base#AddHeaderLevel
" vimwiki#base#RemoveHeaderLevel
"}}}

" LINK functions {{{
" vimwiki#base#apply_template

" s:clean_url
" vimwiki#base#normalize_link_helper
" vimwiki#base#normalize_imagelink_helper

" s:normalize_link_syntax_n
function! s:normalize_link_syntax_n() " {{{ function! s:normalize_link_syntax_n() " {{{
let lnum = line('.') let lnum = line('.')


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


endfunction " }}} endfunction " }}}


" s:normalize_link_syntax_v
function! s:normalize_link_syntax_v() " {{{ function! s:normalize_link_syntax_v() " {{{
let lnum = line('.') let lnum = line('.')
let sel_save = &selection let sel_save = &selection
Expand All @@ -99,13 +280,23 @@ function! s:normalize_link_syntax_v() " {{{


endfunction " }}} endfunction " }}}


" normalize_link " vimwiki#base#normalize_link
function! vimwiki#markdown_base#normalize_link(is_visual_mode) "{{{ function! vimwiki#markdown_base#normalize_link(is_visual_mode) "{{{
if !a:is_visual_mode if 0
call s:normalize_link_syntax_n() " Syntax-specific links
elseif visualmode() ==# 'v' && line("'<") == line("'>") else
" action undefined for 'line-wise' or 'multi-line' visual mode selections if !a:is_visual_mode
call s:normalize_link_syntax_v() call s:normalize_link_syntax_n()
elseif visualmode() ==# 'v' && line("'<") == line("'>")
" action undefined for 'line-wise' or 'multi-line' visual mode selections
call s:normalize_link_syntax_v()
endif
endif endif
endfunction "}}} endfunction "}}}


" }}}

" -------------------------------------------------------------------------
" Load syntax-specific Wiki functionality
" -------------------------------------------------------------------------

46 changes: 34 additions & 12 deletions doc/vimwiki.txt
Expand Up @@ -9,7 +9,7 @@
|___| |___| |_| |_||__| |__||___| |___| |_||___| ~ |___| |___| |_| |_||__| |__||___| |___| |_||___| ~




Version: 2.0 'stu' Version: 2.0.1 'stu'


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


Inline links: > Inline link: >
[Looks like this](URL) [Looks like this](URL)
Image links: > Image link: >
![Looks like this](URL) ![Looks like this](URL)
The URL can be anything recognized by vimwiki as a raw URL. The URL can be anything recognized by vimwiki as a raw URL.
Expand All @@ -623,10 +623,26 @@ Reference-style links: >
a) [Link Name][Id] a) [Link Name][Id]
b) [Id][], using the "implicit link name" shortcut b) [Id][], using the "implicit link name" shortcut
Vimwiki treats reference style links just like default "Wikilinks". In the Reference style links must always include *two* consecutive pairs of
current implementation: the Id field must be a valid wiki page name, [-brackets, and field entries can not use "[" or "]".
reference style links must always include *two* consecutive pairs of
[-brackets, and entries can not use "[" or "]".
NOTE: (in Vimwiki's current implementation) Reference-style links are a hybrid
of Vimwiki's default "Wikilink" and the tradition reference-style link.

If the Id is defined elsewhere in the source, as per the Markdown standard: >
[Id]: URL
then the URL is opened with the system default handler. Otherwise, Vimwiki
treats the reference-sytle link as a Wikilink, interpreting the Id field as a
wiki page name.

Highlighting of existing links when |vimwiki-option-maxhi| is activated
identifies links whose Id field is not defined, either as a reference-link or
as a wiki page.

To scan the page for new or changed definitions for reference-links, simply
re-open the page ":e<CR>".




------------------------------------------------------------------------------ ------------------------------------------------------------------------------
Expand Down Expand Up @@ -1193,29 +1209,29 @@ Use the :VimwikiTable command to create a default table with 5 columns and 2
rows: > rows: >
| | | | | | | | | | | |
|---+---+---+---+---| |---|---|---|---|---|
| | | | | | | | | | | |
< <


Tables are auto-formattable. Let's add some text into first cell: > Tables are auto-formattable. Let's add some text into first cell: >
| First Name | | | | | | First Name | | | | |
|---+---+---+---+---| |---|---|---|---|---|
| | | | | | | | | | | |
< <


Whenever you press <TAB>, <CR> or leave Insert mode, the table is formatted: > Whenever you press <TAB>, <CR> or leave Insert mode, the table is formatted: >
| First Name | | | | | | First Name | | | | |
|------------+---+---+---+---| |------------|---|---|---|---|
| | | | | | | | | | | |
< <


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


2.0.1 'stu'~

* Follow (i.e. open target of) markdown reference-style links.
* Bug fixes.


2.0 'stu'~ 2.0 'stu'~


This release is partly incompatible with previous. This release is partly incompatible with previous.

*
Summary ~ Summary ~


* Quick page-link creation. * Quick page-link creation.
Expand Down

0 comments on commit d19cc85

Please sign in to comment.