File tree 2 files changed +10
-2
lines changed 2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -38,7 +38,14 @@ export function toSlug(string) {
38
38
}
39
39
40
40
export default ( props ) => {
41
- var slug = toSlug ( props . toSlug || props . children ) ;
41
+ var usedSlugs = props . usedSlugs || { } ;
42
+ var append = '' ;
43
+ var loopCount = 0 ;
44
+ do {
45
+ var slug = toSlug ( ( props . toSlug || props . children ) + append ) ;
46
+ append = '-' + ( ++ loopCount ) ;
47
+ } while ( usedSlugs [ slug ] ) ;
48
+ usedSlugs [ slug ] = slug ;
42
49
var Heading = 'h' + props . level ;
43
50
var url = props . url || '' ;
44
51
Original file line number Diff line number Diff line change @@ -745,6 +745,7 @@ function Parser(options) {
745
745
this . tokens = [ ] ;
746
746
this . token = null ;
747
747
this . options = options || marked . defaults ;
748
+ this . usedSlugs = { } ;
748
749
}
749
750
750
751
/**
@@ -816,7 +817,7 @@ Parser.prototype.tok = function() {
816
817
}
817
818
case 'heading' : {
818
819
return (
819
- < Header url = { this . options . url } level = { this . token . depth } toSlug = { this . token . text } >
820
+ < Header url = { this . options . url } level = { this . token . depth } toSlug = { this . token . text } usedSlugs = { this . usedSlugs } >
820
821
{ this . inline . output ( this . token . text ) }
821
822
</ Header >
822
823
) ;
You can’t perform that action at this time.
0 commit comments