Code Monkey home page Code Monkey logo

Comments (17)

mzlogin avatar mzlogin commented on May 22, 2024

Can you describe your scenario more detail? I don't know if you want to jumping "in Vim" from TOC to headline, or "in generated HTML files somewhere".

from vim-markdown-toc.

assaf758 avatar assaf758 commented on May 22, 2024

sure.
I mean jumping in vim. vimwiki has functionality to jump by following a link (for example in TOC). Although it supports markdown, it does not create a markdown TOC. So I would like to use vim-markdown-toc for this.
it works nicely.
the one exception where it does not work is when the heading contains spaces. vim-markdown-toc creates the TOC entry with dashes replacing the spaces, and this confuses vimwiki logic, and as a result jumping does not work.

from vim-markdown-toc.

mzlogin avatar mzlogin commented on May 22, 2024

I just tried vimwiki and use vim-markdown-toc to generate a TOC for a Markdown file, I found add an option not to replace space with dash is not enough to make it work fine. There are many other differences between GFM and vimwiki anchor links generate principles. For example .,~? and Chinese punctuations in headline are ignored in GFM generated anchor links, while not in vimwiki.

So more work is needed to make vim-markdown-toc to support vimwiki. I'll woking on it, and notify you here when I make a progress.

from vim-markdown-toc.

mzlogin avatar mzlogin commented on May 22, 2024

Oops...After I read through vimwiki doc, I found that vimwiki already provided a command to generate TOC, and even an option to keep TOC up to date automatically.

Table of Contents                    *vimwiki-toc* *vimwiki-table-of-contents*

You can create a "table of contents" at the top of your wiki file.
The commando |:VimwikiTOC| creates the magic header >
  = Contents =
in the current file and below it a list of all the headers in this file as
links, so you can directly jump to specific parts of the file.

For the indentation of the list, the value of |vimwiki-option-list_margin| is
used.

If you don't want the TOC to sit in the very first line, e.g. because you have
a modeline there, put the magic header in the second or third line and run
:VimwikiTOC to update the TOC.

If English is not your preferred language, set the option
|g:vimwiki_toc_header| to your favorite translation.

If you want to keep the TOC up to date automatically, use the option
|vimwiki-option-auto_toc|.

See https://raw.githubusercontent.com/vimwiki/vimwiki/master/doc/vimwiki.txt.

So, that would be a better solution for you.

from vim-markdown-toc.

assaf758 avatar assaf758 commented on May 22, 2024

yes, I tried vimwiki-toc at first, but turns out it does not support markdown format when creating the toc, even if I configure markdown as the format for the wiki.
I agree it would have been better if vimwiki added proper support for this (vimwiki/vimwiki#200) but since its open since 4/2016 I'm not holding my breath :-)
This is why I tried vim-mardkown-toc..

from vim-markdown-toc.

mzlogin avatar mzlogin commented on May 22, 2024

I created a Pull Request in vimwiki repository for this:

vimwiki/vimwiki#296

It's a solution to solve your problem. I think it is more elegant than I add support for vimwiki in vim-markdown-toc.

What you need to do is add 'markdown_toc': 1 to your g:vimwiki_list, like this:

let g:vimwiki_list = [{
            \ 'path'    :   '~/vimwiki/',
            \ 'syntax'  :   'markdown',
            \ 'ext'     :   '.mkd',
            \ 'auto_toc':   1,
            \ 'markdown_toc' : 1
            \ }]

Hope it can be merged. Before that, you can use my fork of vimwiki as workaround:

https://github.com/mzlogin/vimwiki

from vim-markdown-toc.

assaf758 avatar assaf758 commented on May 22, 2024

man, this is great, thanks! :-) works perfectly!

BTW, I'm not really sure there is a need for a config option, since if the 'syntax' chosen is 'markdown' you can probably assume the user wants its TOC to be markdown as well..

Anyway, thanks again!

from vim-markdown-toc.

mzlogin avatar mzlogin commented on May 22, 2024

I also considered that issue if there is a need for a config option, and finally I add it. I think it's import to provide forward compatibility. I'm not sure all 'markdown' syntax users of vimwiki want their TOC to be markdown as well, so now don't change the default behavior may better. And if the demand is strong, users like you can request vimwiki to change the default value of markdown_toc to 1 later.

from vim-markdown-toc.

assaf758 avatar assaf758 commented on May 22, 2024

Actually I think there is an issue with the approach you have taken in your pr.
Since the url is not markdown compliant, its not parsed correctly when viewing the wiki file from a browser.
(there is no such problem with vim-markdown-toc)

from vim-markdown-toc.

mzlogin avatar mzlogin commented on May 22, 2024

Because the anchor links for headings generated by vimwiki and other Markdown engines like GFM are different.

So it is impossible to jump normally in both Vim(use vimwiki's jump feature) and Browser now.

A workaround is to use vim-markdown-toc maintain toc for viewing in Browser, and use tagbar to jump in Vim, like this:

I wrote an article about view and jump to Markdown headings in Vim with tagbar before, you can see it http://mazhuang.org/2016/08/03/add-outline-for-markdown-in-vim/. (It's in Chinese, if you don't know Chinese, you may read it in http://translate.google.com)

Maybe I can add a feature in vim-markdown-toc to support jump in Vim, without vimwiki. But now I'm not sure how to implement it elegantly, or is it possible to implement that perfectly.

If you have any more idea about this, welcome to continue the discussion.

from vim-markdown-toc.

assaf758 avatar assaf758 commented on May 22, 2024

ok, I see this is complex :-)
I'll use both TOC for now..
Another question:
is it possible to add an option for a prefix to each link created by vim-markdown-toc?
I'm using github 'gollum ' wiki, and it expects jump links like so:
#contents_
so in this case the prefix will be 'contents_'

from vim-markdown-toc.

mzlogin avatar mzlogin commented on May 22, 2024

I did not find that GitHub Wiki jump links need contents_ prefix, can you show a example wiki page link?

from vim-markdown-toc.

assaf758 avatar assaf758 commented on May 22, 2024

I dont have my wiki available to public access.
You can see it by installing gollum on your machine and then serving markdown file to your browser.

from vim-markdown-toc.

mzlogin avatar mzlogin commented on May 22, 2024

To work with gollum, why not use TOC tag provided by gollum?

ref https://github.com/gollum/gollum/wiki#table-of-contents-toc-tag

from vim-markdown-toc.

assaf758 avatar assaf758 commented on May 22, 2024

right, I missed that feature. thanks!

from vim-markdown-toc.

mzlogin avatar mzlogin commented on May 22, 2024

@assaf758 There is a good news. My patch for vimwiki was accepted, so you can use the newest official vimwiki to maintain Markdown style toc links now and doesn't need the markdown_toc option in vimrc any more.

See vimwiki/vimwiki#483

Please tell me after you switch the plugin to official version, and then I can delete my fork of vimwiki.

from vim-markdown-toc.

bratekarate avatar bratekarate commented on May 22, 2024

FYI, I submitted this PR to vimwiki that enhances vimwiki anchor links so that dashes can be used in the url instead of whitespaces and it is case-insensitives.

That means GFM anchor links work now inside vimwiki as well. It is not yet accepted, but I was asked to create a PR by maintainers, so I guess chances are good that it will be merged at some point to dev branch.

TOC works perfectly inside vimwiki now for me :) thanks this plugin. Anyone who wants to test it can check out the branch of my fork.

from vim-markdown-toc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.