vim-markdown
vim-markdown copied to clipboard
Link in Nested List
Hello. First off thanks for the fantastic plugin :)
I've noticed a small bug that causes links in nested lists to go un-highlighted if the list items are indented. It seems that after 4 indentations, the line is treated as a code block, while I believe it is valid to indent lines 4 characters if they are in a sub-level list item (at least github thinks so).
You can replicate this bug as follows:
- Top level list item
Blah blah blah blah blah...- Sub-level list item
Blah blah blah blah blah... this is a link
- Sub-level list item
I spent a lot of time tinkering with this particular edge case before I gave up. Markdown is just too expressive to highlight with regexes alone, and regexes is all I got. Patches welcome.
I was afraid of that. I'll tinker with it a bit and see if I can come up with anything. Not overly important, though. Thanks for the reply!
Some time ago I wrote a multimarkdown syntax plugin that supported nested paragraphs and I can say it was a PITA. I got it working, I got it clean, but it's not trivial code at all.
I think many people just use fenced code blocks nowadays, so maybe you could add an option to disable indented code blocks. At least that would be a cheap workaround for people using this style of markdown.
Anyway, it's also too easy to do a syn clear markdownCodeBlock in your .vimrc so maybe the extra option is not worthy at all.
@tpope What would be the best autocmd to use @memeplex 's suggestion? Would clearing it once at, say, Answering my own question, it appears that since markdown syntax file is read only when opening an md file, trying VimEnter, be sufficient?VimEnter leads only to an error message. Using autocmd BufNewFile,BufReadPost *.md syn clear markdownCodeBlock instead appears to work. It would be slightly cleaner to specify on the filetype rather than the extension, but this is sufficient for my current purposes.
Also, it might be worth adding this possible issue and this solution to the README, since it took some time for me to even consider that this might be an interpretation-as-a-code-block issue, even then I almost missed this issue thread.
Fenced code blocks go against the spirit of Markdown (readable plain test), so I will not be adding an option that in any way implies an endorsement of them.
I would expect au Syntax markdown to work, provided it is defined after :syntax on. An after/syntax/markdown.vim should definitely work.
Thanks Tim. I realize your first sentence is about adding an option, but in case you meant that regarding the README suggestion as well, consider that a lot of people may have no use for codeblocks at all - using Markdown simply for easy formatting (which described at least 80% of my usage and probably 100% for some people) - and so disabling indented code blocks does not necessarily mean an endorsement of fenced code blocks. You could even phrase it as "If you wish for highlighting on sub-sub-lists and do not use code blocks in your Markdown, ...".
In any case, au Syntax markdown has worked, and I've further added these two lines to get highlighting on the list marker character of sub-sub-lists too:
autocmd Syntax markdown syn match markdownListMarker
\ "\%(\t\| \+\)[-*+]\%(\s\+\S\)\@=" contained
autocmd Syntax markdown syn match markdownOrderedListMarker
\ "\%(\t\| \+\)\<\d\+\.\%(\s\+\S\)\@=" contained
(Basically, changing the original (\t\| \{0,4}\) in syntax/markdown.vim to (\t\| \+\).
I understand tpope's position, but I can suggest a workaround for interested users. If you're okay with only fenced blocks being recognized by the syntax highlighter, you can have highlighting in nested lists by adding this to your ~/.vim/after/syntax/markdown.vim:
" recognize triple-quoted regions as code
syntax region markdownFencedCodeBlock matchgroup=markdownCodeDelimiter keepend start="```" end="```"
" replace markdownCodeBlock with markdownFencedCodeBlock to avoid highlighting 4-space indented regions as code
syn cluster markdownBlock contains=markdownH1,markdownH2,markdownH3,markdownH4,markdownH5,markdownH6,markdownBlockquote,markdownListMarker,markdownOrderedListMarker,markdownFencedCodeBlock,markdownRule