SidOfc / mkdx

A vim plugin that adds some nice extra's for working with markdown documents
https://www.vim.org/scripts/script.php?script_id=5620
MIT License
482 stars 13 forks source link

auto numbering and checkboxes creation when nested sometimes does not work #147

Closed m-fonseca closed 3 years ago

m-fonseca commented 3 years ago

OS type:

Vim:

Vim version: NVIM v0.5.0-dev+1211-g6db3ba9df

Using mkdx 186cf8c

Reproduce steps:

Using

/*

1. test1
    1.1. test2

Hitting enter after test2 does not create a numbered list automatically. This also happens on checkboxes. The key is they have to be nested and there has to be a / in there above it. I don't know what it doesn't like about '/' but it throws things off (syntax highlighting also is changed).

Expected:

Hitting enter after test2 should auto create 1.1.1

Actual:

It doesn't create 1.1.1

Marco

SidOfc commented 3 years ago

Hey Marco! You're finding a lot of things related to the * character :sweat_smile:. The asterisk is used for multiple things in markdown such as italic e.g. *italic* and list items: * list item. Markdown does not have a strict spec about this unfortunately.

The reason you're seeing syntax highlight glitches is because again, the syntax highlighter thinks you're trying to italicize text. This happens because you typed /*. This is also not something that mkdx handles but rather vim-markdown.

Since you use asterisks in ways that the syntax highlighter and my plugin don't like you may like this trick: try escaping them with a \ e.g. /\* will fix your syntax highlighting and pressing enter in a (nested) list will also work again. This should also just show /* in the rendered HTML output.

image

One last thing, hitting enter after test2 should not create 1.1.1 but rather 1.2 :) As usual cheers for the feedback :+1:, if anything sounds harsh here, know that it is not intended!

As for this issue, I'll leave it open until you've read it and had a chance to reply, feel free to close it if you agree this is an alright solution as well.

m-fonseca commented 3 years ago

So if your wondering to yourself what the heck I'm doing with the markdown, I have some preprocessor directives in it (c sytle, hence /*). This also makes the workaround you mentioned not possible for me. I've expect some syntax problems and what not because of this, but I guess I didn't expect it to throw of the whole file, so at this point I guess is more of a question of robustness with funny markdown :).

A couple of questions/things that don't make sense to me though, if you will so indulge:

  1. If /* is a multi-line type of statement, then why doesn't all the syntax highlighting below it reflect that. Thats one of the reasons this threw me. /* can be way above the numbered list, and you don't realize there is a problem because the syntax highlighting is fine until you get to the nested list.
  2. Why does the list numbering work for the first level but not the second level when in this /* mode.
  3. Seems more then just an italics problem though, why does an empty * alone without the / not cause this problem? e.g. instead of /* If I have a some text is fine *
  4. So if this was addressed in vim-markdown would it automatically cause mkdx to behave like I expect?

Either way, this sounds like a vim-markdown issue. So I will close.

Right you are about the 1.2 vs 1.1.1 :)

SidOfc commented 3 years ago

Oke I understand the asterisk issues a little bit better now since you've clarified these are preprocessor directives. As for your questions/misc things:

  1. A character or word can match more than 1 highlight group, so if another highlight group is applied such as list item styling after an opening /* then the list item styling will also stick around and overwrite the /* styles. Custom/preprocessor syntax within markdown is always a bit tricky, though it can be contained within tag delimiters such as <directive a="b"></directive> for example.
  2. Hmmn I didn't check that actually, my current assumption would be that mkdx's enter handler relies on syntax highlight detection to cope with multi-line list items perhaps?
  3. If a line starts with just a * it is not treated as ['markdownItalic', markdownItalicDelimiter'] highlight but as [] (no highlight). When it's just a * you need to type a character before it becomes ['markdownItalic', markdownItalicDelimiter'] so for example, *a also breaks since it highlights as italic.
  4. Well, the reason mkdx list completion is failing is only because of italic highlighting, if that's gone it will work how you'd expect.

Hope this clarifies things a bit, I might check out enter handler to see if I can improve it but not sure if it's really necessary if that highlight can be fixed instead.