WikiLink aliases (#181)

* Added ability to remove link alias

* Added spaces regex 'note | alias' will be displayed correctly.

* show_backlinks

* find_friends

* Fixed simple link processing

* updated style

hide link body when it's aliased

* Review fix

* syntax review fix

* more fixeS

* Documentation

* format fix

* Added documentation
This commit is contained in:
Ilia Ilinykh
2022-11-14 22:34:52 +03:00
committed by GitHub
parent de4502bd55
commit 611d2923d3
3 changed files with 34 additions and 8 deletions

View File

@@ -475,10 +475,18 @@ groups:
- `tkBrackets` : the brackets surrounding the link title - `tkBrackets` : the brackets surrounding the link title
- `tkHighlight` : ==highlighted== text (non-standard markdown) - `tkHighlight` : ==highlighted== text (non-standard markdown)
- `tkTag` : well, tags - `tkTag` : well, tags
- `tkAliasedLink` : link with alias
- `tkHighlightedAliasedLink` : link with alias in `tkAliasedLink`
- `tkLinkAlias` : body of the link (left part of `[[aaa|bbb]]`)
- `tkLinkBody` : alias of the link (right part of `[[aaa|bbb]]`)
`tkHighlight`, has nothing to do with links but I added it anyway, since I like `tkHighlight`, has nothing to do with links but I added it anyway, since I like
highlighting text when taking notes. highlighting text when taking notes.
Plugin supports wiki-link aliases: `[[value|alias]]`. These links will be
concealed to `[[alias]]` if `conceallevel=2`.
I also like the navigation buttons of the calendar to appear less prevalent, so I also like the navigation buttons of the calendar to appear less prevalent, so
I redefine the `CalNavi` class as well. I redefine the `CalNavi` class as well.
@@ -736,6 +744,9 @@ Note links~
`[[A cool title#^xxxxxxxx]]` ....... links to the paragraph with id ^xxxxxxxx `[[A cool title#^xxxxxxxx]]` ....... links to the paragraph with id ^xxxxxxxx
within the note named 'A cool title' within the note named 'A cool title'
`[[A cool title|xxxxxxxx]]` ........ links note 'A cool title' with using
name.
`[[#Heading 27]]` .................. links to the heading 'Heading 27' within `[[#Heading 27]]` .................. links to the heading 'Heading 27' within
all notes all notes

View File

@@ -173,6 +173,14 @@ local function escape(s)
return string.gsub(s, "[%%%]%^%-$().[*+?]", "%%%1") return string.gsub(s, "[%%%]%^%-$().[*+?]", "%%%1")
end end
local function remove_alias(link)
local split_index = string.find(link, "%s*|")
if split_index ~= nil and type(split_index) == "number" then
return string.sub(link, 0, split_index - 1)
end
return link
end
local function file_exists(fname) local function file_exists(fname)
if fname == nil then if fname == nil then
return false return false
@@ -1629,12 +1637,13 @@ local function FindFriends(opts)
vim.cmd("normal yi]") vim.cmd("normal yi]")
local title = vim.fn.getreg('"0') local title = vim.fn.getreg('"0')
title = remove_alias(title)
title = title:gsub("^(%[)(.+)(%])$", "%2") title = title:gsub("^(%[)(.+)(%])$", "%2")
builtin.live_grep({ builtin.live_grep({
prompt_title = "Notes referencing `" .. title .. "`", prompt_title = "Notes referencing `" .. title .. "`",
cwd = M.Cfg.home, cwd = M.Cfg.home,
default_text = "\\[\\[" .. title .. "\\]\\]", default_text = "\\[\\[" .. title .. "([#|].+)?\\]\\]",
find_command = M.Cfg.find_command, find_command = M.Cfg.find_command,
attach_mappings = function(_, map) attach_mappings = function(_, map)
actions.select_default:replace(picker_actions.select_default) actions.select_default:replace(picker_actions.select_default)
@@ -1965,7 +1974,7 @@ local function ShowBacklinks(opts)
prompt_title = "Search", prompt_title = "Search",
cwd = M.Cfg.home, cwd = M.Cfg.home,
search_dirs = { M.Cfg.home }, search_dirs = { M.Cfg.home },
default_text = "\\[\\[" .. title .. "(#.+)*\\]\\]", default_text = "\\[\\[" .. title .. "([#|].+)?\\]\\]",
find_command = M.Cfg.find_command, find_command = M.Cfg.find_command,
attach_mappings = function(_, map) attach_mappings = function(_, map)
actions.select_default:replace(picker_actions.select_default) actions.select_default:replace(picker_actions.select_default)
@@ -2181,6 +2190,7 @@ local function FollowLink(opts)
-- we are in a link -- we are in a link
vim.cmd("normal yi]") vim.cmd("normal yi]")
title = vim.fn.getreg('"0') title = vim.fn.getreg('"0')
title = remove_alias(title)
title = title:gsub("^(%[)(.+)(%])$", "%2") title = title:gsub("^(%[)(.+)(%])$", "%2")
else else
-- we are in an external [link] -- we are in an external [link]

View File

@@ -8,8 +8,8 @@ unlet b:current_syntax
syn region Comment matchgroup=Comment start="<!--" end="-->" contains=tkTag keepend syn region Comment matchgroup=Comment start="<!--" end="-->" contains=tkTag keepend
syntax region tkLink matchgroup=tkBrackets start=/\[\[/ end=/\]\]/ display oneline syntax region tkLink matchgroup=tkBrackets start=/\[\[/ end=/\]\]/ display oneline
syntax region tkHighlight matchgroup=tkBrackets start=/==/ end=/==/ display oneline syntax region tkHighlight matchgroup=tkBrackets start=/==/ end=/==/ display oneline contains=tkHighlightedAliasedLink
syntax match tkTag "\v#[a-zA-ZÀ-ÿ]+[a-zA-ZÀ-ÿ0-9/\-_]*" syntax match tkTag "\v#[a-zA-ZÀ-ÿ]+[a-zA-ZÀ-ÿ0-9/\-_]*"
syntax match tkTag "\v:[a-zA-ZÀ-ÿ]+[a-zA-ZÀ-ÿ0-9/\-_]*:" syntax match tkTag "\v:[a-zA-ZÀ-ÿ]+[a-zA-ZÀ-ÿ0-9/\-_]*:"
@@ -17,20 +17,25 @@ syntax match tkTag "\v:[a-zA-ZÀ-ÿ]+[a-zA-ZÀ-ÿ0-9/\-_]*:"
syntax match tkTagSep "\v\s*,\s*" contained syntax match tkTagSep "\v\s*,\s*" contained
syntax region tkTag matchgroup=tkBrackets start=/^tags\s*:\s*\[\s*/ end=/\s*\]\s*$/ contains=tkTagSep display oneline syntax region tkTag matchgroup=tkBrackets start=/^tags\s*:\s*\[\s*/ end=/\s*\]\s*$/ contains=tkTagSep display oneline
syntax region tkAliasedLink start="\[\[[^\]]\+|" end="\]\]" keepend oneline contains=tkLinkAlias,tkLinkBody
syntax region tkHighlightedAliasedLink start="\[\[[^\]]\+|" end="\]\]" keepend oneline contained contains=tkLinkAlias,tkLinkBody
syntax region tkLinkAlias start="|"ms=s+1 end=".+\]\]"me=e-2 keepend contained
syntax region tkLinkBody start="\[\["ms=s+2 end="|" keepend contained conceal
let b:current_syntax = 'telekasten' let b:current_syntax = 'telekasten'
" " just blue " " just blue
" hi tklink ctermfg=Blue cterm=bold,underline " hi tkLink ctermfg=Blue cterm=bold,underline
" hi tkBrackets ctermfg=gray " hi tkBrackets ctermfg=gray
" " for gruvbox " " for gruvbox
" hi tklink ctermfg=72 cterm=bold,underline " hi tkLink ctermfg=72 cterm=bold,underline
" hi tkBrackets ctermfg=gray " hi tkBrackets ctermfg=gray
" " Highlight ==highlighted== text " " Highlight ==highlighted== text
" hi tkHighlight ctermbg=yellow ctermfg=darkred cterm=bold " hi tkHighlight ctermbg=yellow ctermfg=darkred cterm=bold
" "
" " Tags " " Tags
" hi tkTagSep ctermfg=gray " hi tkTagSep ctermfg=gray
" hi tkTag ctermfg=magenta " hi tkTag ctermfg=magenta