Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VimwikiTOC is broken against headers with link #182

Closed
ryujinno opened this issue Jan 8, 2016 · 4 comments
Closed

VimwikiTOC is broken against headers with link #182

ryujinno opened this issue Jan 8, 2016 · 4 comments

Comments

@ryujinno
Copy link

ryujinno commented Jan 8, 2016

VimwikiTOC is broken against headers with link.
This wiki reproduces the bug.

= Contents =
  - [[#[[http://example.com/|Example Domain]]|[[http://example.com/|Example Domain]]]]

= [[http://example.com/|Example Domain]] =

This bug is not reproduced with old %toc.

@Nudin
Copy link
Member

Nudin commented Dec 19, 2018

A # in a title also breaks VimwikiTOC

@ranebrown ranebrown added this to Needs triage in Bug Triage Deprecated Mar 21, 2019
@ranebrown
Copy link
Contributor

Headers with parenthesis also don't work for markdown syntax but I would guess that will be fixed with #619

@ranebrown ranebrown moved this from Needs triage to Medium Priority in Bug Triage Deprecated Mar 22, 2019
@riazrizvi
Copy link

It looks like VimwikiTOC eats lines containing any rxBulletList symbol, until it finds a non-empty line that doesn't. So if the first heading contains for example a # anywhere, then it is still considered under =Contents= and it will be deleted. If I understand the function of VimwikiTOC, it should stop replacing when a non-empty line does not have a first non-blank character = either #, -, *.

The problem can be fixed by replacing the code to generate rxBulletList in autoload/vimwiki/vars.vim:vimwiki#vars#populate_syntax_vars with this:

  if !empty(g:vimwiki_syntax_variables[a:syntax].bullet_types)
    let g:vimwiki_syntax_variables[a:syntax].rxListBullet =
          \ join( map( map(copy(g:vimwiki_syntax_variables[a:syntax].bullet_types),
          \'vimwiki#u#escape(v:val).'
          \ .'repeat("\\+", g:vimwiki_syntax_variables[a:syntax].recurring_bullets)'
          \ ), 'escape("^s*","s") . (v:val)') , '\|')
  else
    "regex that matches nothing
    let g:vimwiki_syntax_variables[a:syntax].rxListBullet = '$^'
  endif

It prepends a ^\s* to every rxBulletList regex entry, which is used in vimwiki#base#update_listing_in_buffer to replace old TOC.

Since VimwikiGenerateLinks also uses the same regex via vimwiki#base#update_listing_in_buffer, I think it has a similar problem and this will also address that.

The nested map function is a bit complicated IMO. Might be easier to understand and debug if the whole thing was a transparent loop?

tinmarino added a commit to tinmarino/vimwiki that referenced this issue Aug 6, 2020
Problem: VimwikiTOC and follow_link do not support header (anchor) with
link in their body

Solution:
- VimwikiTOC (easy): Create function base.vim s:clean_header_text that
converts [DESC](URL) -> DESC
- follow_link (hard):
-- [[URL]]: was already working due to punctuation removal.
-- [DESC](URL): Search for a potential `]([^)]*)` after every character
@tinmarino
Copy link
Member

Fixed: 69ead3b (see commit message for more info)

Bug Triage Deprecated automation moved this from Medium Priority to Closed Aug 6, 2020
deepredsky pushed a commit to deepredsky/vimwiki that referenced this issue Jan 16, 2021
Problem: VimwikiTOC and follow_link do not support header (anchor) with
link in their body

Solution:
- VimwikiTOC (easy): Create function base.vim s:clean_header_text that
converts [DESC](URL) -> DESC
- follow_link (hard):
-- [[URL]]: was already working due to punctuation removal.
-- [DESC](URL): Search for a potential `]([^)]*)` after every character
jls83 pushed a commit to jls83/vimwiki that referenced this issue Jan 17, 2023
Problem: VimwikiTOC and follow_link do not support header (anchor) with
link in their body

Solution:
- VimwikiTOC (easy): Create function base.vim s:clean_header_text that
converts [DESC](URL) -> DESC
- follow_link (hard):
-- [[URL]]: was already working due to punctuation removal.
-- [DESC](URL): Search for a potential `]([^)]*)` after every character
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

No branches or pull requests

6 participants