mzlogin/vim-markdown-toc

links generated for sections with hyphens not working for Gitlab

vser1 opened this issue ยท 6 comments

vser1 commented

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.

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.

vser1 commented

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

Thanks for your awesome script btw ๐Ÿ‘

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. ๐Ÿ˜„

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.

vser1 commented

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 ๐Ÿ˜Ÿ

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.