SidOfc / mkdx

A vim plugin that adds some nice extra's for working with markdown documents

Home Page:https://www.vim.org/scripts/script.php?script_id=5620

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

References display issue.

samarulmeu opened this issue · comments

Hello! I bother again with a display issue.

So, in the official markdown specifications are defined what are called reference-style links that look something like This is [an example][id] reference-style link with the id defined later [id]: http://example.com/ "Optional Title Here".

The problem is with the way mkdx renders this kind of links as you can see from this screenshot.

footnote

The footnote explanation is nicely displayed, but for the reference there is a strange color for the first word.

Thank you for your help and understanding!

(Sorry for posting only part of the message in the beginning).

Hello again @samarulmeu, In this case I really doubt this is something I should fix in mkdx. The "weird" highlight you see is due to markdownUrl being applied. I think this makes sense in the context of "links" usually not referring to arbitrary text, if I type this in this editor:

[testing][1]
[testing][2]

[1]: https://working.com
[2]: Broken in this editor too

The result is:

testing
[testing][2]

[2]: Broken in this editor too


In this case, if you'd want to see it patched, I think it'd be best if you opened an issue on https://github.com/tpope/vim-markdown which is where this highlight comes from I think (not sure if Vim or Neovim have moved on from this package)

If I understand correctly you borrowed the highlight from vim-markdown. I did not notice till now that if you have a link in the reference part is highlighted (new screenshot) and I think that from here comes the "trouble".

footnote2

Anyhow Markdown does not have some strict implementation, but at least the "official" one should work. I think it is a matter of style and in this case it is some regex expression that it will check if after ]: you have a link or just a word.

In my screenshot you can see that the footnote explanation is rendered as expected. I think you agree with me that it is not pleasing to the eye 😁 the way it is now.

@samarulmeu I do agree with you, it's just that this syntax highlight does not exist in mkdx "itself" i.e. it is not borrowed, it literally is not defined "by" mkdx itself. mkdx "adds" highlighting on top of existing highlighting. I could fix this, but I've already stated many times before that I am not a syntax highlighting expert. More often than not I repurpose syntax highlighting from other plugins.

This is why I added the note to open an issue in the repo of the original implementation of this highlight. That way, not only "mkdx" is fixed, but "all" other vim distros which ship markdown highlighting as well.

The fact that it is "official" and should therefore work should thus be handled not by some random plugin (mkdx) but rather should be handled in the official implementation which is used in either vim/neovim.

Is there a specific reason you want "mkdx" to fix it rather than opening an issue on the official implementation (official as far as I know anyway)?

@SidOfc so I should open an issue at vim-markdown! and then wait to be implemented in vim (and there is a different road for each distribution), as I am not using this plugin.

This is one of the reasons I was preferring to have it in mxdx -- sooner updates.

It is your choice if you want to close it or not. If I have some time I will dig a little and see if I can not have something locally.

Just deciding to open an issue in one repository for "faster updates" instead of preferring the proper place to fix it is definitely not right (for various reasons) unless the original project is dead. You may not know it but you are highly likely using vim-markdown since it comes pre-installed in recent versions of vim or neovim (taken from the first paragraph of tpope/vim-markdown README.md).

That said, I found the "actual" offender: markdownIdDeclaration. The nextgroup=markdownUrl here is why you see the first word highlighted as a URL and the rest being plain (because url pattern matching stops once a space is encountered).

To fix this, you can define your own highlight groups like this in some :h autocmd which triggers whenever :h FileType is triggered for markdown files:

syn match myReferenceSource '.*' skipwhite contained contains=markdownUrl
syn match myReferenceId '^\[[^]^]\+\]: ' oneline skipwhite nextgroup=myReferenceSource
highlight default link myReferenceId Identifier

Which will produce something like this:

image

Now it seems tempting to implement this in mkdx because the solution is literally already written, but I see existing configurations potentially failing due to mkdx all of a sudden "messing up" whatever default highlighting was there and ending up having to implement and document yet another option there which to me does not seem worth it.

Basically, you now have 2 options:

  1. apply the above snippet in your own configuration and taking care to only load it for markdown files
  2. open an issue on tpope/vim-markdown to "patch" this highlight properly

All that said, thank you for your time and thoughts but this one will be closed until it's been proven that there is a significant need for it directly in mkdx.

Thank you for your time and patience!

I followed your advice and opened an issue to the vim-markdown plugin. Now the waiting 😁 . Till then I will use your code, it works perfectly.

@samarulmeu no problem, the least I could do is provide an alternative solution for everyone to use. Thank you for your understanding as well 👍