marksman icon indicating copy to clipboard operation
marksman copied to clipboard

Incorrect link to header generated when header contain link.

Open johnybx opened this issue 2 years ago • 5 comments

Hi, thanks for great LSP server. I noticed that when I use link in header like in the example bellow the server autocompletes incorrect link like in the example:

# Google

test

# [Google link](https://google.com)

test

[google link](#google)
[google link with link](#google-linkhttpsgooglecom)

I believe the second link should omit the url part like this#google-link.

Here is screenshot from neovim how I see autocomplete options for this example:

incorrect-link-screenshot

johnybx avatar Sep 11 '22 13:09 johnybx

Hi @johnybx! Thanks for reporting. Generally, with anchor completions, the anchor text is a slug of the respective header's text. With that said:

  1. I think when a header contains a single link we could make the completion and reference resolution handle this in a special way. But then the question is: does Github understand this kind of anchor links?
  2. What if a header is some text + a link. What do you expect the behavior to be in this case?

As a workaround I could suggest using link definitions, e.g.

# Google

# [Google Link]

[google link]: https://google.com

Would that work for you or you specifically need full inline links in headings? If so, I'm curious what's the use-case?

artempyanykh avatar Sep 11 '22 14:09 artempyanykh

Hi, yes I tested the links in gitlab and also with nvim extension and links work only if anchor slug ignores the link text. Even if heading looks like this

# [test](link) something

I believe the link should be #test-something.

Basically my report was based on the fact that the generated links did not work :).

Currently my use case is developer documentation where heading is most often link to relevant folder or file which is relevant for section.

The workaround looks good, I actually did not even know about that, I will try that in the following days and if it works than I am more than happy to close this 👍.

Thanks for quick response.

johnybx avatar Sep 14 '22 19:09 johnybx

Thanks for the info @johnybx! I do care for the generated slugs to be readable by GitHub/GitLab so if they strip out urls from links in the heading, so should Marksman 🙂 I'll look into it. Meantime, yes do try the workaround.

artempyanykh avatar Sep 14 '22 20:09 artempyanykh

I just tried the workaround and it works but when I define links using link definition than the generate table of contents command is broken

Test table of contents

<!--toc:start-->
- [[Google Link]](#google-link)
<!--toc:end-->

# [Google Link]

[google link]: https://google.com

Should I create another issue for this or is it related enough to have it in single issue?

Edit: It will be probably related after this issue is fixed because with link in header it generates table of content like this:

Test table of contents

<!--toc:start-->
- [Google](#google)
- [[Google link](https://google.com)](#google-linkhttpsgooglecom)
<!--toc:end-->

# Google

test

# [Google link](https://google.com)

johnybx avatar Oct 10 '22 16:10 johnybx

I have a similar issue when the header contains special characters such as underscores.

For instance:

## Table:some_function

If I create a TOC via code actions, it will create a TOC with anchor reference #tablesomefunction. When trying out on GitHub, it seems that the anchor that would work is actually #tablesome_function. Hence it drops the : correctly, but incorrectly also drops the _.

I am aware this does not perfectly match the name of this issue, but it is a very related issue I guess. Would you want me to create a separate issue about this?

f4z3r avatar Mar 06 '24 20:03 f4z3r