From 62d63bcaad768717d9b6447e057e4d7a927ced99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Thu, 4 May 2023 22:58:30 +0200 Subject: [PATCH 1/2] feat!: new option g:wiki_link_creation This option provides a more flexible filetype dependent behaviour. It also deprecates four other options and thus makes configuring wiki.vim easier for most people. And since the new option provides sensible defaults, it also means most people will require less customization. The following options are deprecated: * g:wiki_map_text_to_link * g:wiki_map_create_page * g:wiki_link_extension * g:wiki_link_target_type refer: #296 --- autoload/wiki/complete.vim | 2 +- autoload/wiki/link.vim | 22 +++- autoload/wiki/link/word.vim | 29 +++--- autoload/wiki/page.vim | 30 +++--- doc/wiki.txt | 202 ++++++++++++++++-------------------- plugin/wiki.vim | 22 +++- 6 files changed, 161 insertions(+), 146 deletions(-) diff --git a/autoload/wiki/complete.vim b/autoload/wiki/complete.vim index b994aa7..ed9a859 100644 --- a/autoload/wiki/complete.vim +++ b/autoload/wiki/complete.vim @@ -119,7 +119,7 @@ function! s:completer_wikilink.complete_page(regex) dict abort " {{{2 call map(l:cands, 'strpart(v:val, strlen(l:root)+1)') call map(l:cands, - \ empty(g:wiki_link_extension) + \ empty(wiki#link#get_creator('url_extension')) \ ? 'l:pre . fnamemodify(v:val, '':r'')' \ : 'l:pre . v:val') call s:filter_candidates(l:cands, a:regex) diff --git a/autoload/wiki/link.vim b/autoload/wiki/link.vim index a54d0ac..3366908 100644 --- a/autoload/wiki/link.vim +++ b/autoload/wiki/link.vim @@ -64,6 +64,18 @@ endfunction "}}}1 +function! wiki#link#get_creator(...) abort " {{{1 + let l:ft = expand('%:e') + if empty(l:ft) || index(g:wiki_filetypes, l:ft) < 0 + let l:ft = g:wiki_filetypes[0] + endif + let l:c = get(g:wiki_link_creation, l:ft, g:wiki_link_creation._) + + return a:0 > 0 ? l:c[a:1] : l:c +endfunction + +" }}}1 + function! wiki#link#show(...) abort "{{{1 let l:link = wiki#link#get() @@ -162,16 +174,16 @@ endfunction " }}}1 function! wiki#link#template(url, text) abort " {{{1 - " " Pick the relevant link template command to use based on the users " settings. Default to the wiki style one if its not set. - " + try - return wiki#link#{g:wiki_link_target_type}#template(a:url, a:text) + let l:type = wiki#link#get_creator('link_type') + return wiki#link#{l:type}#template(a:url, a:text) catch /E117:/ call wiki#log#warn( - \ 'Link target type does not exist: ' . g:wiki_link_target_type, - \ 'See ":help g:wiki_link_target_type" for help' + \ 'Target link type does not exist: ' . l:type, + \ 'See ":help g:wiki_link_creation" for help' \) endtry endfunction diff --git a/autoload/wiki/link/word.vim b/autoload/wiki/link/word.vim index ce660ba..a05db89 100644 --- a/autoload/wiki/link/word.vim +++ b/autoload/wiki/link/word.vim @@ -23,22 +23,23 @@ function! s:matcher.toggle_template(text, _) abort " {{{1 " This template returns a wiki template for the provided word(s). It does " a smart search for likely candidates and if there is no unique match, it " asks for target link. + let l:creator = wiki#link#get_creator() - " Allow custom map of text -> url, text (without extension) - if !empty(g:wiki_map_text_to_link) - \ && (type(g:wiki_map_text_to_link) == v:t_func - \ || exists('*' . g:wiki_map_text_to_link)) - let [l:url, l:text] = call(g:wiki_map_text_to_link, [a:text]) - else - let l:url = a:text - let l:text = a:text + " Apply url transformer if available + let l:url = a:text + if has_key(l:creator, 'url_transform') + try + let l:url = l:creator.url_transform(a:text) + catch + call wiki#log#warn('There was a problem with the url transformer!') + endtry endif " Append extension if wanted let l:url_root = l:url - if !empty(g:wiki_link_extension) + if !empty(l:creator.url_extension) \ && strcharpart(l:url, strchars(l:url)-1) !=# '/' - let l:url .= g:wiki_link_extension + let l:url .= l:creator.url_extension let l:url_actual = l:url else let l:url_actual = l:url . '.' . b:wiki.extension @@ -47,7 +48,7 @@ function! s:matcher.toggle_template(text, _) abort " {{{1 " First try local page let l:root_current = expand('%:p:h') if filereadable(wiki#paths#s(printf('%s/%s', l:root_current, l:url_actual))) - return wiki#link#template(l:url, l:text) + return wiki#link#template(l:url, a:text) endif " If we are inside the journal, then links should by default point to the @@ -58,7 +59,7 @@ function! s:matcher.toggle_template(text, _) abort " {{{1 " Check if target matches at wiki root if filereadable(wiki#paths#s(printf('%s/%s', l:root, l:url_actual))) - return wiki#link#template(l:prefix . l:url, l:text) + return wiki#link#template(l:prefix . l:url, a:text) endif else let l:root = l:root_current @@ -73,7 +74,7 @@ function! s:matcher.toggle_template(text, _) abort " {{{1 " Solve trivial cases first if len(l:candidates) == 0 - return wiki#link#template(l:prefix . l:url, l:text) + return wiki#link#template(l:prefix . l:url, a:text) endif " Select with menu @@ -81,7 +82,7 @@ function! s:matcher.toggle_template(text, _) abort " {{{1 let l:choice = wiki#ui#select(l:candidates + [l:new]) return empty(l:choice) ? l:url : ( \ l:choice ==# l:new - \ ? wiki#link#template(l:url, l:text) + \ ? wiki#link#template(l:url, a:text) \ : wiki#link#template(l:prefix . l:choice, '')) endfunction diff --git a/autoload/wiki/page.vim b/autoload/wiki/page.vim index f223bd0..812a1fa 100644 --- a/autoload/wiki/page.vim +++ b/autoload/wiki/page.vim @@ -10,10 +10,14 @@ function! wiki#page#open(...) abort "{{{1 \ : wiki#ui#input(#{info: 'Open page (or create new): '}) if empty(l:page) | return | endif - if !empty(g:wiki_map_create_page) - \ && (type(g:wiki_map_create_page) == v:t_func - \ || exists('*' . g:wiki_map_create_page)) - let l:page = call(g:wiki_map_create_page, [l:page]) + " Apply url transformer if available + let l:link_creator = wiki#link#get_creator() + if has_key(l:link_creator, 'url_transform') + try + let l:page = l:link_creator.url_transform(l:page) + catch + call wiki#log#warn('There was a problem with the url transformer!') + endtry endif call wiki#url#parse('wiki:/' . l:page).follow() @@ -427,7 +431,7 @@ function! s:path_to_url(root, path) abort " {{{1 let l:path = wiki#paths#relative(a:path, a:root) let l:ext = '.' . fnamemodify(l:path, ':e') - return l:ext ==# g:wiki_link_extension + return l:ext ==# wiki#link#get_creator('url_extension') \ ? l:path \ : fnamemodify(l:path, ':r') endfunction @@ -477,24 +481,26 @@ endfunction " }}}1 function! s:convert_links_to_html(lines) abort " {{{1 - if g:wiki_link_target_type ==# 'md' + let l:creator = wiki#link#get_creator() + + if l:creator.link_type ==# 'md' let l:rx = '\[\([^\\\[\]]\{-}\)\]' - \ . '(\([^\(\)\\]\{-}\)' . g:wiki_link_extension + \ . '(\([^\(\)\\]\{-}\)' . l:creator.url_extension \ . '\(#[^#\(\)\\]\{-}\)\{-})' let l:sub = '[\1](\2.html\3)' - elseif g:wiki_link_target_type ==# 'wiki' - let l:rx = '\[\[\([^\\\[\]]\{-}\)' . g:wiki_link_extension + elseif l:creator.link_type ==# 'wiki' + let l:rx = '\[\[\([^\\\[\]]\{-}\)' . l:creator.url_extension \ . '\(#[^#\\\[\]]\{-}\)' \ . '|\([^\[\]\\]\{-}\)\]\]' let l:sub = '\[\[\1.html\2|\3\]\]' - elseif g:wiki_link_target_type ==# 'org' - let l:rx = '\[\[\([^\\\[\]]\{-}\)' . g:wiki_link_extension + elseif l:creator.link_type ==# 'org' + let l:rx = '\[\[\([^\\\[\]]\{-}\)' . l:creator.url_extension \ . '\(#[^#\\\[\]]\{-}\)' \ . '\]\[\([^\[\]\\]\{-}\)\]\]' let l:sub = '\[\[\1.html\2|\3\]\]' else return wiki#log#error( - \ 'g:wiki_link_target_type must be `wiki`, `md`, or `org` to', + \ 'g:wiki_link_creator link_type must be `wiki`, `md`, or `org` to', \ 'replace link extensions on export.' \) endif diff --git a/doc/wiki.txt b/doc/wiki.txt index 00592dc..491c54d 100644 --- a/doc/wiki.txt +++ b/doc/wiki.txt @@ -371,8 +371,6 @@ syntax highlighting and folding. Recommended settings if you want to use this: >vim let g:wiki_filetypes = ['wiki'] - let g:wiki_link_target_type = '' - let g:wiki_link_extension = '' lists.vim ~ https://github.com/lervag/lists.vim @@ -496,13 +494,13 @@ OPTIONS *wiki-config-options* \} *g:wiki_filetypes* - List of filetypes for which |wiki.vim| should be enabled. If you want to - make Markdown the default filetype, add it as the first element to the list, - e.g.: >vim + List of filetype extensions for which |wiki.vim| should be enabled. Notice + that file extensions are not always the same as the filetype. For example, + the common extension for Markdown is `.md`, whereas the filetype is called + `markdown`. The option should list the file extensions. - let g:wiki_filetypes = ['md', 'wiki'] -< - See also |g:wiki_link_extension|, which is often relevant in many filetypes. + The first element of the list is considered the default filetype where that + is relevant. Default: `['md']` @@ -731,11 +729,76 @@ OPTIONS *wiki-config-options* \ 'link_url_parser': { b, d, p -> 'journal:' . d } \} -*g:wiki_link_extension* - Specify the extension that should be applied to wiki links. This should be - in the format `.ext`, e.g. `.md` or `.wiki`. +*g:wiki_link_creation* + A dictionary to configure how links are created from text for any given + filetype. Filetypes are specified by file extension so as to correspond with + |g:wiki_filetypes|, that is, we use `md` and not `markdown`. + + The corresponding value is a dictionary of options. If there is no key for + the current filetype, then the fallback key `"_"` is used. + + The valid options are: + + link_type ~ + A string that specifies the type of link to create. Possible values: + + `md` (|wiki-link-markdown|) + Markdown style links. + + `wiki` (|wiki-link-wiki|) + Wiki style links. + + `org` (|wiki-link-orgmode|) + Orgmode style links. + + `adoc_xref_bracket` (|wiki-link-adoc-xref|) + `adoc_xref_inline` + AsciiDoc cross-reference style links (angled brackets style or + inline `xref:...` style). + + url_extension ~ + A string that, if not empty, will be appended to the target url. + + url_transform ~ + A |Funcref| for a function used to transform the text to the desired + URL. This can also be an |anonymous-function|. If it is undefined, the + the original text will be taken as the URL. + The function requires a single string argument and should return the + target URL without any file extension. This is useful e.g. to substitute + space characters, apply URL encoding, or similar. + An example may be useful. The following configuration will convert all + characters to lowercase and substitute each set of one or more spaces + into a single dash character. >vim + + let g:wiki_link_creation = { + \ 'markdown': { + \ 'link_type': 'md', + \ 'url_extension': '.md', + \ 'url_transform': { x -> + \ substitute(tolower(x), '\s\+', '-', 'g') }, + \ }, + \} +< + Default: >vim - Default: `'.md'` + let g:wiki_link_creation = { + \ 'md': { + \ 'link_type': 'md', + \ 'url_extension': '.md', + \ }, + \ 'org': { + \ 'link_type': 'org', + \ 'url_extension': '.org', + \ }, + \ 'adoc': { + \ 'link_type': 'adoc_xref_bracket', + \ 'url_extension': '', + \ }, + \ '_': { + \ 'link_type': 'wiki', + \ 'url_extension': '', + \ }, + \} *g:wiki_link_toggle_on_follow* This option allows disabling the toggle behaviour in |WikiLinkFollow| where @@ -745,29 +808,6 @@ OPTIONS *wiki-config-options* Default: 1 -*g:wiki_link_target_type* - This option may be used to pick the default style of link that will be used. - - Available styles for the default target type are: - - `md` (|wiki-link-markdown|) - Markdown style links. - - `wiki` (|wiki-link-wiki|) - Wiki style links. - - `org` (|wiki-link-orgmode|) - Orgmode style links. - - `adoc_xref_bracket` (|wiki-link-adoc-xref|) - `adoc_xref_inline` - AsciiDoc cross-reference style links (angled brackets style or inline - `xref:...` style). - - Toggling between link types can still be achieved using |WikiLinkToggle|. - - Default: `'md'` - *g:wiki_link_toggles* This option specifies the template for toggling a specific type of link with |WikiLingToggle| or |(wiki-link-toggle)|. @@ -804,69 +844,6 @@ OPTIONS *wiki-config-options* \ 'url': 'wiki#link#md#template', \} -*g:wiki_map_create_page* - This option may be used to specify a map or transformation for page names - provided to |WikiOpen|. For example: >vim - - let g:wiki_map_create_page = 'MyFunction' - - function MyFunction(name) abort - let l:name = wiki#get_root() . '/' . a:name - - " If the file is new, then append the current date - return filereadable(l:name) - \ ? a:name - \ : a:name . '_' . strftime('%Y%m%d') - endfunction -< - With the above setting, if one enters a page name "foo" for |WikiOpen| on - the date 2020-04-11, the page "foo_20200411" will be created. - - The option value should be a string (the `name` of the function) or - a |Funcref|. The latter only works in neovim when the option is defined from - Lua with |lua-vim-variables|, e.g. >lua - - vim.g.wiki_map_create_page = function(x) return x:lower() end -< - Default: `''` - -*g:wiki_map_text_to_link* - This option may be used to transform text before creating a new link with - |WikiLinkToggle| (or related mappings). The option value should be a string - (the `name` of the function) or a |Funcref|. The latter only works in neovim - when the option is defined from Lua with |lua-vim-variables|, similar to - this: >lua - - vim.g.wiki_map_text_to_link = function(x) - return { x:lower(), x } - end -< - The specified function must take a single argument and return two values. - The following signature should be descriptive: >vim - - let [url, text] = TextToLink(text_raw) -< - Here `text_raw` is the text that should be transformed to a link composed - of `url` and `text`. An example may be more enlightening: >vim - - let g:wiki_map_text_to_link = 'MyTextToLink' - - function MyTextToLink(text) abort - return [substitute(tolower(a:text), '\s\+', '-', 'g'), a:text] - endfunction -< - This specifies that transformations will look like the following, - given that other settings are at their defaults: > - - Hello world → [[hello-world|Hello World]] - Some text → [[some-text|Some text]] -< - Note: The actual resulting link also depends on these options: - - |g:wiki_link_extension| - - |g:wiki_link_target_type| - - Default: `''` - *g:wiki_mappings_use_defaults* Whether or not to use default mappings (see |wiki-mappings-default|). The allowed values are: @@ -1223,9 +1200,11 @@ the commands are also available as mappings of the form `(wiki-[name])`. *(wiki-open)* *WikiOpen* Open (or create) a page. Asks for user input to specify the page name. When - not already inside a wiki, the wiki root is given by |g:wiki_root|. If - |g:wiki_map_create_page| is specified, it will be used to transform the - input name before opening/creating the page. + not already inside a wiki, the wiki root is given by |g:wiki_root|. + + The settings from |g:wiki_link_creation| are applied based on the current + 'filetype'. If the filetype is not specified or if it is not listed in + |g:wiki_filetypes|, then the first filetype in this list is assumed. *(wiki-journal)* *WikiJournal* @@ -1313,11 +1292,11 @@ the commands are also available as mappings of the form `(wiki-[name])`. *(wiki-link-toggle-operator)* |map-operator| *WikiLinkToggle* Toggle a link. That is, this converts a link from one type to another based - on the value of |g:wiki_link_toggles|. Pure text is converted to a link of - type |g:wiki_link_target_type|, and if |g:wiki_map_text_to_link| is - specified, it will be used to transform the link before creating it. + on the value of |g:wiki_link_toggles|. - The following rules apply when converting text to a link. + Additionally, this command and the mappings can be used to convert regular + text to a link. The behaviour is controlled by |g:wiki_link_creation| and + follows the following set of rules. If we are inside the journal: ~ @@ -1375,7 +1354,7 @@ the commands are also available as mappings of the form `(wiki-[name])`. *(wiki-journal-index)* *WikiJournalIndex* Insert a sorted list of links to all journal pages below the cursor. It uses - the link style specified by |g:wiki_link_target_type|. + the link type specified in |g:wiki_link_creation| for the current filetype. *(wiki-journal-next)* *WikiJournalNext* @@ -1426,8 +1405,11 @@ the commands are also available as mappings of the form `(wiki-[name])`. -link_ext_replace ~ Set to true to replace in-wiki link extensions with html. This enables - in-browser wiki navigation. Requires `ext` be set to `html` and for - |g:wiki_link_extension| to be non-empty to have any meaningful effect. + in-browser wiki navigation, but for it to work well, it requires that: + + 1. `-ext` is set to `html`, and + 2. |g:wiki_link_creation| should have a `url_transform` that appends + the extension. -output ~ Set output directory where the exported file is stored. Relative paths are @@ -1601,8 +1583,8 @@ The mappings that act on links are listed in |wiki-mappings-default|. The most notable default mappings are: - A link may be followed with ``. - `` used on normal text (not on a link) will transform the text into - a link of the type specified by |g:wiki_link_target_type|. This also works - in visual mode. + a link of the type specified by |g:wiki_link_creation|. This also works in + visual mode. - Similarly, `gl` may be used to turn operated text into a link. - One may use `` to navigate back after following a link. - `wf` can be used to transform a link between different types (see diff --git a/plugin/wiki.vim b/plugin/wiki.vim index a9f3970..f73e64d 100644 --- a/plugin/wiki.vim +++ b/plugin/wiki.vim @@ -44,8 +44,24 @@ call wiki#init#option('wiki_journal_index', { \ 'link_text_parser': { b, d, p -> d }, \ 'link_url_parser': { b, d, p -> 'journal:' . d } \}) -call wiki#init#option('wiki_link_extension', '.md') -call wiki#init#option('wiki_link_target_type', 'md') +call wiki#init#option('wiki_link_creation', { + \ 'md': { + \ 'link_type': 'md', + \ 'url_extension': '.md', + \ }, + \ 'org': { + \ 'link_type': 'org', + \ 'url_extension': '.org', + \ }, + \ 'adoc': { + \ 'link_type': 'adoc_xref_bracket', + \ 'url_extension': '', + \ }, + \ '_': { + \ 'link_type': 'wiki', + \ 'url_extension': '', + \ }, + \}) call wiki#init#option('wiki_link_toggle_on_follow', 1) call wiki#init#option('wiki_link_toggles', { \ 'wiki': 'wiki#link#md#template', @@ -57,8 +73,6 @@ call wiki#init#option('wiki_link_toggles', { \ 'shortcite': 'wiki#link#md#template', \ 'url': 'wiki#link#md#template', \}) -call wiki#init#option('wiki_map_create_page', '') -call wiki#init#option('wiki_map_text_to_link', '') call wiki#init#option('wiki_mappings_use_defaults', 'all') call wiki#init#option('wiki_month_names', [ \ 'January', 'February', 'March', 'April', 'May', 'June', 'July', From d6b0788979757f5f62fbd28ad2d31a6327d87578 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Thu, 4 May 2023 23:01:12 +0200 Subject: [PATCH 2/2] test: update tests to use g:wiki_link_creation --- test/init.vim | 2 -- test/test-complete/test-markdown.vim | 2 -- test/test-init/test-buffer-root.vim | 3 +- test/test-init/test-proper-extension.vim | 3 +- test/test-links/test-adoc.vim | 9 +----- test/test-links/test-create-special.vim | 41 +++++++----------------- test/test-links/test-open-markdown.vim | 9 ++---- test/test-links/test-open-orgmode.vim | 9 ++---- test/test-markdown/test.vim | 2 -- test/test-orgmode/test.vim | 2 -- test/test-page/test-rename-md.vim | 1 - test/test-page/test-rename-org.vim | 1 - test/test-tags/test-custom-yaml.vim | 1 - test/wiki-adoc/minimal.vim | 1 - 14 files changed, 23 insertions(+), 63 deletions(-) diff --git a/test/init.vim b/test/init.vim index 8db5bc6..3ac71c8 100644 --- a/test/init.vim +++ b/test/init.vim @@ -11,5 +11,3 @@ let g:testroot = fnamemodify(expand(''), ':p:h:h') let g:wiki_cache_persistent = 0 let g:wiki_filetypes = ['wiki'] -let g:wiki_link_target_type = 'wiki' -let g:wiki_link_extension = '' diff --git a/test/test-complete/test-markdown.vim b/test/test-complete/test-markdown.vim index 7d3a1a5..8340c3e 100644 --- a/test/test-complete/test-markdown.vim +++ b/test/test-complete/test-markdown.vim @@ -1,8 +1,6 @@ source ../init.vim let g:wiki_filetypes = ['md'] -let g:wiki_link_extension = '.md' -let g:wiki_link_target_type = 'md' filetype plugin indent on runtime plugin/wiki.vim diff --git a/test/test-init/test-buffer-root.vim b/test/test-init/test-buffer-root.vim index 40bd40a..f9ac662 100644 --- a/test/test-init/test-buffer-root.vim +++ b/test/test-init/test-buffer-root.vim @@ -2,10 +2,11 @@ source ../init.vim let g:wiki_root = g:testroot . '/wiki-basic' let g:wiki_filetypes = ['wiki', 'md'] -let g:wiki_link_extension = '.wiki' runtime plugin/wiki.vim +let g:wiki_link_creation._.url_extension = '.wiki' + silent edit test.md " Should use .wiki extension when we navigate to the wiki diff --git a/test/test-init/test-proper-extension.vim b/test/test-init/test-proper-extension.vim index 4529ec0..17c1422 100644 --- a/test/test-init/test-proper-extension.vim +++ b/test/test-init/test-proper-extension.vim @@ -2,10 +2,11 @@ source ../init.vim let g:wiki_root = g:testroot . '/wiki-basic' let g:wiki_filetypes = ['wiki', 'md'] -let g:wiki_link_extension = '.wiki' runtime plugin/wiki.vim +let g:wiki_link_creation._.url_extension = '.wiki' + silent edit test.md silent call wiki#goto_index() diff --git a/test/test-links/test-adoc.vim b/test/test-links/test-adoc.vim index 54ac974..d267b42 100644 --- a/test/test-links/test-adoc.vim +++ b/test/test-links/test-adoc.vim @@ -1,18 +1,11 @@ source ../init.vim -let g:wiki_link_target_type = 'adoc_xref_bracket' let g:wiki_filetypes = ['adoc'] runtime plugin/wiki.vim -" Test toggle on selection (g:wiki_link_extension should not matter here) -silent edit ../wiki-adoc/index.adoc -normal! 15G -silent execute "normal f.2lve\(wiki-link-toggle-visual)" -call assert_equal('Some text, cf. <>.', getline('.')) -bwipeout! -let g:wiki_link_extension = '.adoc' +" Test toggle on selection silent edit ../wiki-adoc/index.adoc normal! 15G silent execute "normal f.2lve\(wiki-link-toggle-visual)" diff --git a/test/test-links/test-create-special.vim b/test/test-links/test-create-special.vim index 7408cd9..0bdc004 100644 --- a/test/test-links/test-create-special.vim +++ b/test/test-links/test-create-special.vim @@ -1,13 +1,11 @@ source ../init.vim -let g:wiki_map_text_to_link = 'TextToLink' - -function TextToLink(text) abort - return [substitute(tolower(a:text), '\s\+', '-', 'g'), a:text] -endfunction - runtime plugin/wiki.vim +" Specify url transformer +let g:wiki_link_creation._.url_transform = + \ { x -> substitute(tolower(x), '\s\+', '-', 'g') } + " Test toggle normal on regular markdown links using wiki style links silent edit ../wiki-basic/index.wiki normal! 3G @@ -31,7 +29,7 @@ call assert_equal('[[pokémon|Pokémon]]', getline('.')) " Test toggle normal on regular markdown links using md style links bwipeout! -let g:wiki_link_target_type = 'md' +let g:wiki_link_creation._.link_type = 'md' silent edit ../wiki-basic/index.wiki normal! 3G silent execute "normal vt.\(wiki-link-toggle-visual)" @@ -40,8 +38,7 @@ call assert_equal('[This is a wiki](this-is-a-wiki).', getline('.')) " Test toggle normal on regular markdown links using md style links with the " markdown extension bwipeout! -let g:wiki_link_target_type = 'md' -let g:wiki_link_extension = '.md' +let g:wiki_link_creation._.url_extension = '.md' silent edit ../wiki-basic/index.wiki normal! 3G silent execute "normal vt.\(wiki-link-toggle-visual)" @@ -53,8 +50,8 @@ call assert_equal('[TestSubDirLink/](testsubdirlink/)', getline('.')) " Test toggle normal on regular orgmode links using md style links with the " orgmode extension bwipeout! -let g:wiki_link_target_type = 'org' -let g:wiki_link_extension = '.org' +let g:wiki_link_creation._.link_type = 'org' +let g:wiki_link_creation._.url_extension = '.org' silent edit ../wiki-basic/index.wiki normal! 3G silent execute "normal vt.\(wiki-link-toggle-visual)" @@ -65,8 +62,8 @@ call assert_equal('[[testsubdirlink/][TestSubDirLink/]]', getline('.')) " Test toggle normal on regular markdown links using md style links in journal bwipeout! -let g:wiki_link_target_type = 'md' -let g:wiki_link_extension = '' +let g:wiki_link_creation._.link_type = 'md' +let g:wiki_link_creation._.url_extension = '' silent edit ../wiki-basic/index.wiki normal! 3G silent execute 'let b:wiki.in_journal=1' @@ -74,27 +71,13 @@ silent execute "normal vt.\(wiki-link-toggle-visual)" call assert_equal('[This is a wiki](this-is-a-wiki).', getline('.')) " Test toggle normal on regular markdown links using md style links in journal -" without `g:wiki_map_text_to_link` +" without url transformer bwipeout! -let g:wiki_link_target_type = 'md' -let g:wiki_link_extension = '' -let g:wiki_map_text_to_link = '' +unlet g:wiki_link_creation._.url_transform silent edit ../wiki-basic/index.wiki normal! 3G silent execute 'let b:wiki.in_journal=1' silent execute "normal vt.\(wiki-link-toggle-visual)" call assert_equal('[This is a wiki](This is a wiki).', getline('.')) -bwipeout! -let g:wiki_link_target_type = 'md' -let g:wiki_link_extension = '' -let g:wiki_map_text_to_link = 'TextToLink2' -function TextToLink2(text) abort - return [a:text, substitute(a:text, '-', ' ', 'g')] -endfunction -silent edit ../wiki-basic/index.wiki -normal! 14G -silent execute 'normal glt.' -call assert_equal('[This is a wiki](This-is-a-wiki).', getline('.')) - call wiki#test#finished() diff --git a/test/test-links/test-open-markdown.vim b/test/test-links/test-open-markdown.vim index f28287e..c742565 100644 --- a/test/test-links/test-open-markdown.vim +++ b/test/test-links/test-open-markdown.vim @@ -1,16 +1,13 @@ source ../init.vim -function MyFunction(text) abort - return substitute(tolower(a:text), '\s\+', '-', 'g') -endfunction - let g:wiki_filetypes = ['md'] -let g:wiki_link_extension = '.md' -let g:wiki_map_create_page = 'MyFunction' let g:wiki_root = g:testroot . '/wiki-basic' runtime plugin/wiki.vim +let g:wiki_link_creation.md.url_transform = + \ { x -> substitute(tolower(x), '\s\+', '-', 'g') } + silent WikiIndex call assert_equal(g:wiki_root . '/index.md', expand('%')) diff --git a/test/test-links/test-open-orgmode.vim b/test/test-links/test-open-orgmode.vim index aaa954f..8a005ee 100644 --- a/test/test-links/test-open-orgmode.vim +++ b/test/test-links/test-open-orgmode.vim @@ -1,16 +1,13 @@ source ../init.vim -function MyFunction(text) abort - return substitute(tolower(a:text), '\s\+', '-', 'g') -endfunction - let g:wiki_filetypes = ['org'] -let g:wiki_link_extension = '.org' -let g:wiki_map_create_page = 'MyFunction' let g:wiki_root = g:testroot . '/wiki-basic' runtime plugin/wiki.vim +let g:wiki_link_creation.org.url_transform = + \ { x -> substitute(tolower(x), '\s\+', '-', 'g') } + silent WikiIndex call assert_equal(g:wiki_root . '/index.org', expand('%')) diff --git a/test/test-markdown/test.vim b/test/test-markdown/test.vim index 1aaec51..987357a 100644 --- a/test/test-markdown/test.vim +++ b/test/test-markdown/test.vim @@ -2,8 +2,6 @@ source ../init.vim " Initial load of wiki.vim let g:wiki_filetypes = ['md'] -let g:wiki_link_extension = '.md' -let g:wiki_link_target_type = 'md' runtime plugin/wiki.vim " Test open existing wiki with no settings diff --git a/test/test-orgmode/test.vim b/test/test-orgmode/test.vim index 180dcda..06dc6d6 100644 --- a/test/test-orgmode/test.vim +++ b/test/test-orgmode/test.vim @@ -2,8 +2,6 @@ source ../init.vim " Initial load of wiki.vim let g:wiki_filetypes = ['org'] -let g:wiki_link_extension = '.org' -let g:wiki_link_target_type = 'org' runtime plugin/wiki.vim " Test open existing wiki with no settings diff --git a/test/test-page/test-rename-md.vim b/test/test-page/test-rename-md.vim index 4c62c2c..421bd77 100644 --- a/test/test-page/test-rename-md.vim +++ b/test/test-page/test-rename-md.vim @@ -1,6 +1,5 @@ source ../init.vim let g:wiki_filetypes = ['md'] -let g:wiki_link_extension = '.md' runtime plugin/wiki.vim silent edit wiki-tmp/test\ 2.md diff --git a/test/test-page/test-rename-org.vim b/test/test-page/test-rename-org.vim index c883f07..d80c5e1 100644 --- a/test/test-page/test-rename-org.vim +++ b/test/test-page/test-rename-org.vim @@ -1,6 +1,5 @@ source ../init.vim let g:wiki_filetypes = ['org'] -let g:wiki_link_extension = '.org' runtime plugin/wiki.vim silent edit wiki-tmp/test\ 2.org diff --git a/test/test-tags/test-custom-yaml.vim b/test/test-tags/test-custom-yaml.vim index a904f26..5ee6591 100644 --- a/test/test-tags/test-custom-yaml.vim +++ b/test/test-tags/test-custom-yaml.vim @@ -4,7 +4,6 @@ runtime plugin/wiki.vim let g:wiki_log_verbose = 0 let g:wiki_filetypes = ['md'] -let g:wiki_link_extension = '.md' let g:wiki_tag_parsers = [ \ g:wiki#tags#default_parser, \ { diff --git a/test/wiki-adoc/minimal.vim b/test/wiki-adoc/minimal.vim index 11f3b6b..0bf7543 100644 --- a/test/wiki-adoc/minimal.vim +++ b/test/wiki-adoc/minimal.vim @@ -1,7 +1,6 @@ source ../init.vim syntax enable -let g:wiki_link_target_type = 'adoc_xref_bracket' let g:wiki_filetypes = ['adoc'] runtime plugin/wiki.vim