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

Lines inside fenced code blocks that start with an octothorpe are interpreted as headers and break folding #35

Open
rpdelaney opened this issue Aug 13, 2019 · 7 comments

Comments

@rpdelaney
Copy link

This looks very much along the lines of #1. Possibly related to #6 also (but I kinda doubt it).

Using vim-markdown-folding with vim-plug, on 3f35acf. I'm observing a problem when editing this file I'm working on.

Looks like this:

#     Pre-OS prep                             [17 lines]-----------------------------------------------------------------------------------
##    Installation media                      [13 lines]-----------------------------------------------------------------------------------
##    Create partitions                       [4 lines]------------------------------------------------------------------------------------
#     gdisk /dev/nvme0n1                      [7 lines]------------------------------------------------------------------------------------
##    Create LUKS container                   [4 lines]------------------------------------------------------------------------------------
#     cryptsetup luksFormat --type luks1 --use-random --hash whirlpool --iter-time 5000 /dev/nvme0n1p2 [4 lines]---------------------------
##    O/S Filesystem                          [7 lines]------------------------------------------------------------------------------------
###   Create and mount LVM volumes            [6 lines]------------------------------------------------------------------------------------
# vgcreate volgroup0 /dev/mapper/cryptlvm
# lvcreate volgroup0 -L 32G -n lvswap
#     lvcreate volgroup0 -l 100%FREE -n lvroot [5 lines]-----------------------------------------------------------------------------------
###   Create btrfs filesystem                 [4 lines]------------------------------------------------------------------------------------
# mkfs.btrfs -L root /dev/volgroup0/lvroot
# mkswap -L swap /dev/volgroup0/lvswap
#     swapon -L swap                          [56 lines]-----------------------------------------------------------------------------------
##    O/S                                     [4 lines]------------------------------------------------------------------------------------

I would expect something more like this (maybe with different counts of folded lines):

#     Pre-OS prep                             [17 lines]-----------------------------------------------------------------------------------
##    Installation media                      [13 lines]-----------------------------------------------------------------------------------
##    Create partitions                       [4 lines]------------------------------------------------------------------------------------
##    Create LUKS container                   [4 lines]------------------------------------------------------------------------------------
##    O/S Filesystem                          [7 lines]------------------------------------------------------------------------------------
###   Create and mount LVM volumes            [6 lines]------------------------------------------------------------------------------------
###   Create btrfs filesystem                 [4 lines]------------------------------------------------------------------------------------
##    O/S                                     [4 lines]------------------------------------------------------------------------------------
@masukomi
Copy link
Owner

My apologies for the delay.

Thanks for the nice writeup and use-case @rpdelaney

I'll try and set aside some time to look at this. If you come up with a PR that addresses it I'll happily merge it.

@masukomi
Copy link
Owner

masukomi commented Nov 19, 2019

quick note for future me:

As the title suggests, the problem is essentially that it's not ignoring headings contained in code fences.

eg

```
# cryptsetup luksFormat --type luks1 --use-random --hash whirlpool --iter-time 5000 /dev/nvme0n1p2
```

@wesrer
Copy link

wesrer commented May 16, 2020

@masukomi Any progress on this?

@noperator
Copy link

Also experiencing this issue and would love a fix! Thanks for a great plugin @masukomi 🙂

@masukomi
Copy link
Owner

masukomi commented Jul 4, 2020

@wesrer just haven't gotten around to working on this. Will happily accept PRs (cc @noperator ) ;)

@noperator
Copy link

Strangely, I'm encountering this issue a bit inconsistently. I tried to reproduce @rpdelaney's example above by downloading the file as is, and opening it in vim.

wget https://raw.githubusercontent.com/rpdelaney/iris-setup/a73f04ab1d0d0cc587d40893af2bf48c7eb81ba7/PRE_OS.md
vim PRE_OS.md

Here's what I'm seeing:

#     Pre-OS prep                             [17 lines]-----------------------
##    Installation media                      [13 lines]-----------------------
##    Create partitions                       [12 lines]-----------------------
##    Create LUKS container                   [9 lines]------------------------
##    O/S Filesystem                          [7 lines]------------------------
###   Create and mount LVM volumes            [14 lines]-----------------------
###   Create btrfs filesystem                 [63 lines]-----------------------
##    O/S                                     [4 lines]------------------------

I'll report back here if I can reproduce an octothorpe within fenced code blocks that breaks folding.

noperator added a commit to noperator/dotfiles that referenced this issue Jul 18, 2020
@noperator
Copy link

I noticed that wherever leading octothorpes inside fenced code blocks were interpreted by this plugin as a header, those lines were also highlighted as headers—i.e., for some reason, Vim's included syntax highlighting wasn't recognizing those lines as being inside of a code block. That's likely the root issue here since this plugin's folding.vim, in turn, relies on the aforementioned syntax highlighting to determine whether a given line is inside of a code block or not:

function! LineIsFenced(lnum)
if exists("b:current_syntax") && b:current_syntax ==# 'markdown'
" It's cheap to check if the current line has 'markdownCode' syntax group
return HasSyntaxGroup(a:lnum, '\vmarkdown(Code|Highlight)')
else
" Using searchpairpos() is expensive, so only do it if syntax highlighting
" is not enabled
return s:HasSurroundingFencemarks(a:lnum)
endif
endfunction

I think I solved this issue (in my case, at least) by following some guidance from tpope/vim-markdown (Vim's included syntax highlighting):

Syntax highlight is synchronized in 50 lines. It may cause collapsed highlighting at large fenced code block. In the case, please set larger value in your vimrc:

let g:markdown_minlines = 100

Note that setting too large value may cause bad performance on highlighting.

I kept increasing g:markdown_minlines until this problem went away (i.e., until the folded headers looked right), settling at 1000 with no recognizable performance issues. Here's my .vimrc for your reference; masukomi/vim-markdown-folding is the only plugin I'm using, installed with Vim's native package loading.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants