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

Link in Nested List #4

Open
kflorence opened this issue Feb 3, 2011 · 7 comments
Open

Link in Nested List #4

kflorence opened this issue Feb 3, 2011 · 7 comments

Comments

@kflorence
Copy link

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...
@tpope
Copy link
Owner

tpope commented Feb 3, 2011

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.

@kflorence
Copy link
Author

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!

@memeplex
Copy link

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.

@digital-carver
Copy link

@tpope What would be the best autocmd to use @memeplex 's suggestion? Would clearing it once at, say, VimEnter, be sufficient? Answering my own question, it appears that since markdown syntax file is read only when opening an md file, trying 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.

@tpope
Copy link
Owner

tpope commented Aug 4, 2015

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.

@digital-carver
Copy link

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\| \+\).

@rampion
Copy link

rampion commented Oct 15, 2015

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

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

5 participants