Skip to content

Fix duplicate heading id - #1401

Merged
joshbruce merged 3 commits into
markedjs:masterfrom
styfle:slugger2
Dec 31, 2018
Merged

Fix duplicate heading id#1401
joshbruce merged 3 commits into
markedjs:masterfrom
styfle:slugger2

Conversation

@styfle

@styflestyfle commented Dec 20, 2018

Copy link
Copy Markdown
Member

Marked version: 0.5.2

Markdown flavor: All

Description

This fixes several bugs involving headerIds: true.

This adds a new export marked.Slugger.

I added several more tests to cover duplicates as well as ampersands.

Contributor

  • Test(s) exist to ensure functionality and minimize regression

Committer

In most cases, this should be a different person than the contributor.

  • Draft GitHub release notes have been updated.
  • CI is green (no forced merge required).
  • Merge PR

Comment threadtest/unit/marked-spec.js Outdated
@UziTech

UziTech commented Dec 20, 2018

Copy link
Copy Markdown
Member

we also need to test for Flet/github-slugger#20

expect(slugger.slug('test 1')).toBe('test-1');expect(slugger.slug('test')).toBe('test');expect(slugger.slug('test')).toBe('test-2');

and

expect(slugger.slug('foo'),'foo')expect(slugger.slug('foo'),'foo-1')expect(slugger.slug('foo 1'),'foo-1-1')expect(slugger.slug('foo-1'),'foo-1-2')expect(slugger.slug('foo'),'foo-2')

@styfle

Copy link
Copy Markdown
MemberAuthor

That's an interesting problem you found. I fixed this PR, thanks 👍

@UziTechUziTech left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great 👍

@styfle

Copy link
Copy Markdown
MemberAuthor

@davisjam@joshbruce After this PR lands, I can do a new release. Can you take a look?

@joshbruce
joshbruce merged commit dfbc9a1 into markedjs:masterDec 31, 2018
@joshbruce

Copy link
Copy Markdown
Member

Just to make sure I'm up to speed on the header conversation and whatnot. We're adding slugger to fix a defect, which is header duplication. We are still experiencing issues with unicode characters like Japanese and other glyph languages. And we are still progressing toward dropping header ID generation in the future. Yeah?

@styfle
styfle deleted the slugger2 branch December 31, 2018 21:26
@styfle

Copy link
Copy Markdown
MemberAuthor

@joshbruce This PR fixes non-latin char headings as well as duplicate IDs.

In the future we could drop support and rely on github-slugger. That PR #1354 (which was removing slugger from marked) was rejected. So I made this PR.

@tmorehouse

tmorehouse commented Jan 1, 2019

Copy link
Copy Markdown

@styfle@joshbruce@UziTech

We're receiving errors for this latest update (^0.5.2 -> ^0.6.0):

8:57:27 PM: WARNING in ./src/components/table/README.md
8:57:27 PM: Module build failed (from ./node_modules/markdown-loader/index.js):
8:57:27 PM: TypeError: Cannot read property 'slug' of undefined
8:57:27 PM: Please report this to https://github.com/markedjs/marked.
8:57:27 PM: at Renderer.heading (/opt/build/repo/node_modules/marked/lib/marked.js:962:17)
8:57:27 PM: at Parser.tok (/opt/build/repo/node_modules/markdown-loader/node_modules/marked/lib/marked.js:1179:28)
8:57:27 PM: at Parser.parse (/opt/build/repo/node_modules/markdown-loader/node_modules/marked/lib/marked.js:1130:17)
8:57:27 PM: at Function.Parser.parse (/opt/build/repo/node_modules/markdown-loader/node_modules/marked/lib/marked.js:1112:17)
8:57:27 PM: at marked (/opt/build/repo/node_modules/markdown-loader/node_modules/marked/lib/marked.js:1543:19)
8:57:27 PM: at Object.module.exports (/opt/build/repo/node_modules/markdown-loader/index.js:14:12)

@styfle

Copy link
Copy Markdown
MemberAuthor

Are you overwriting the renderer methods?
See the release notes for breaking changes.

https://github.com/markedjs/marked/releases/tag/v0.6.0

If so, try passing new Slugger()
If not, please file a new issue with steps to reproduce.

Thanks!

@tmorehouse

Copy link
Copy Markdown

We are adding a wrapper on the table renderer so that must be it. Will try restoring the slugger handler.

@tmorehouse

tmorehouse commented Jan 1, 2019

Copy link
Copy Markdown

It appears that markdown-loader is using 0.5.x, which is causing our issue (as we are passing it a new renderer instance with code and table overrides), but our renderer is v0.6.0, which has a different calling signature (the slugger argument), compared to v0.5.x

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicate Heading IDs Hash links with "&" are not converted the same way as github links

4 participants

@styfle@UziTech@joshbruce@tmorehouse