Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

links generated for sections with hyphens not working for Gitlab #36

Open
vser1 opened this issue Sep 26, 2017 · 6 comments
Open

links generated for sections with hyphens not working for Gitlab #36

vser1 opened this issue Sep 26, 2017 · 6 comments

Comments

@vser1
Copy link

vser1 commented Sep 26, 2017

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.

@mzlogin
Copy link
Owner

mzlogin commented Sep 26, 2017

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
Copy link
Author

vser1 commented Sep 26, 2017

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

Thanks for your awesome script btw 👍

@mzlogin
Copy link
Owner

mzlogin commented Sep 26, 2017

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
Copy link
Owner

mzlogin commented Sep 26, 2017

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 added a commit that referenced this issue Sep 26, 2017
@vser1
Copy link
Author

vser1 commented Sep 26, 2017

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 😟

@mzlogin
Copy link
Owner

mzlogin commented Sep 26, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants