vim-markdown-toc icon indicating copy to clipboard operation
vim-markdown-toc copied to clipboard

links generated for sections with hyphens not working for Gitlab

Open vser1 opened this issue 8 years ago • 6 comments

Since you do not support GitLab, my issue is mor a backlog for other users.

Since GitHub keeps hyphens and GitLab deletes them when converting a header to an anchor.

The following code is valid for GitHub but not for GitLab

# Test code
<!-- vim-markdown-toc GFM -->

* [This subsection has an - in it](#this-subsection-has-a---in-it)

<!-- vim-markdown-toc -->

## This subsection has a - in it

To make it work, I had to add the following regex in GetHeadingLinkGFM (line 123):

let l:headingLink = substitute(l:headingLink, "-\\+", "-", "g")  # Converts successive hyphens to only one

Maybe you could easily add support for GitLab too, rules to create header anchors are summarized here.

The file generating anchors for headers in GitHub is to be found here. I'm not proficient in ruby but I don't see anything about deleting successive hyphens.

vser1 avatar Sep 26 '17 08:09 vser1

Thanks @vser1

I'm using GitLab, too. I'll look into it, and consider if to add support for GitLab.

You can reference how GitHub handles subsequent hyphens in anchors in https://github.com/jch/html-pipeline/blob/master/lib/html/pipeline/toc_filter.rb.

If we are going to support GitLab, I think it's better to not combine GitHub and GitLab support code, even they are both called GFM.

mzlogin avatar Sep 26 '17 09:09 mzlogin

@mzlogin I've updated my bug report to remove the erroneous code and reference the github file.

Thanks for your awesome script btw :+1:

vser1 avatar Sep 26 '17 09:09 vser1

I think your solution can work, it seems that GitHub and GitLab shared most logic in generated anchors for headings except successive hyphens.

So I'm going to add a command :GenTocGitLab to support GitLab with your solution. I hope you can help me to complete the test cases, and report bad cases if some error happened in the future. 😄

mzlogin avatar Sep 26 '17 09:09 mzlogin

Oh oh... According to GitLab docs, it uses Redcarpet, maybe what I need to do is to enhancement Redcarpet supporting. 😄

Redcarpet take this rule two or more hyphens in a row are converted to one, your can see this in my code L151.

https://docs.gitlab.com/ee/user/markdown.html#gitlab-flavored-markdown-gfm


Update: sadly that most of my test cases for Redcarpet failure on GitLab.

mzlogin avatar Sep 26 '17 10:09 mzlogin

Indeed, misread this point about GitLab using redcarpet.

I see on my test case two errors:

# Tests

<!-- vim-markdown-toc Redcarpet -->

* [Part](#part)
* [Part](#part)
* [Part/Section](#part-section)

<!-- vim-markdown-toc -->

<!-- vim-markdown-toc GFM -->

* [Part](#part)
* [Part](#part-1)
* [Part/Section](#partsection)

<!-- vim-markdown-toc -->
## Part
## Part
## Part/Section

The GFM toc is correct, not the RedCarpet. I don't know RedCarpet's specification but I fear not being able to differentiate two headers with same name is a flaw of your implementation :worried:

vser1 avatar Sep 26 '17 12:09 vser1

Yes. It's likely to be a problem.

I used to support Redcarpet for Jekyll blog working with GitHub Pages, but last year, GitHub announced only support kramdown as Markdown engine for GitHub Pages, so I don't have Redcarpet test environment now.

mzlogin avatar Sep 26 '17 12:09 mzlogin