masukomi / vim-markdown-folding

Fold markdown documents by section.
248 stars 43 forks source link

Folding breaks on particular .md file #41

Open frankitox opened 4 years ago

frankitox commented 4 years ago

Hi! I just encountered a problem when folding, if I have the following markdown in a file:

# First

``` 1 2 3 4 5

7 ```

first

* first * second * third

# Second

second

Then when I close the fold it 'eats' the second heading. So it goes from

image

to

image

Let me know if you can reproduce it. I tried only loading this plugin but the issue persists. I'm using nvim if that helps.

NVIM v0.4.3
Build type: RelWithDebInfo
LuaJIT 2.0.5
Compilation: /usr/bin/gcc-5 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -O2 -g -DMIN_LOG_LEVEL=3 -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wvla -fstack-protector-strong -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -I/home/travis/build/neovim/bot-ci/build/neovim/build/config -I/home/travis/build/neovim/bot-ci/build/neovim/src -I/home/travis/build/neovim/bot-ci/build/neovim/.deps/usr/include -I/usr/include -I/home/travis/build/neovim/bot-ci/build/neovim/build/src/nvim/auto -I/home/travis/build/neovim/bot-ci/build/neovim/build/include
Compiled by travis@travis-job-9a287301-34f2-4b86-92e3-462594f51f36

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/home/travis/build/neovim/bot-ci/build/neovim/build/nvim.AppDir/usr/share/nvim"

Run :checkhealth for more info
frankitox commented 4 years ago

Alright, from what I could found the problem is it interprets the second title as inside fences. Apparently HasSyntaxGroup is what doesn't work properly

https://github.com/masukomi/vim-markdown-folding/blob/3f35acfb753cc9ea22182400b075c5b6e896ad71/after/ftplugin/markdown/folding.vim#L68-L70

As a workaround I simply added to my ~/.vimrc:

autocmd FileType markdown let b:current_syntax=''

Other solution is to add tpope's markdown plugin. tpope's plugin breaks in other places.