From cbab80b86c24fa52f78adc6fe4fd00390ed6607f Mon Sep 17 00:00:00 2001 From: Michael Kolodny Date: Mon, 4 Nov 2013 13:16:08 -0500 Subject: [PATCH 1/2] fix(ngdocs): remove duplicate header ids --- docs/spec/domSpec.js | 7 ++++++- docs/src/dom.js | 10 ++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/docs/spec/domSpec.js b/docs/spec/domSpec.js index d10db9dc7e82..3e736a4be731 100644 --- a/docs/spec/domSpec.js +++ b/docs/spec/domSpec.js @@ -9,11 +9,16 @@ describe('dom', function() { }); describe('html', function() { - it('should add ids to all h tags', function() { + it('should add ids to h tags', function() { dom.html('

Some Header

'); expect(dom.toString()).toContain('

Some Header

'); }); + it('should not add ids to h tags that have ids', function() { + dom.html('

Some Header

'); + expect(dom.toString()).toContain('

Some Header

'); + }); + it('should collect anchors too', function() { dom.html('

Xxx and bar '); expect(dom.anchors).toContain('foo'); diff --git a/docs/src/dom.js b/docs/src/dom.js index e696faf4c1c7..7eb0ce6eea69 100644 --- a/docs/src/dom.js +++ b/docs/src/dom.js @@ -81,9 +81,15 @@ DOM.prototype = { self.currentHeaders[level - 1] = normalizeHeaderToId(content); self.currentHeaders.length = level; - var id = idFromCurrentHeaders(self.currentHeaders); + var id, idAttr = /\sid=["'](.+?)["']/.exec(attrs); + if (idAttr === null) { + id = idFromCurrentHeaders(self.currentHeaders); + attrs += ' id="' + id + '"'; + } else { + id = idAttr[1]; + } self.anchors.push(id); - return '' + content + ''; + return '' + content + ''; }); // collect anchors From 1e51798e26014a21abfef3beae4190c76d72fe3b Mon Sep 17 00:00:00 2001 From: Michael Kolodny Date: Fri, 8 Nov 2013 12:33:57 -0500 Subject: [PATCH 2/2] override existing header ids --- docs/spec/domSpec.js | 4 ++-- docs/src/dom.js | 11 +++-------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/docs/spec/domSpec.js b/docs/spec/domSpec.js index 3e736a4be731..cb4c00f250cb 100644 --- a/docs/spec/domSpec.js +++ b/docs/spec/domSpec.js @@ -14,8 +14,8 @@ describe('dom', function() { expect(dom.toString()).toContain('

Some Header

'); }); - it('should not add ids to h tags that have ids', function() { - dom.html('

Some Header

'); + it('should override existing h tag ids', function() { + dom.html('

Some Header

'); expect(dom.toString()).toContain('

Some Header

'); }); diff --git a/docs/src/dom.js b/docs/src/dom.js index 7eb0ce6eea69..cb15215df866 100644 --- a/docs/src/dom.js +++ b/docs/src/dom.js @@ -81,15 +81,10 @@ DOM.prototype = { self.currentHeaders[level - 1] = normalizeHeaderToId(content); self.currentHeaders.length = level; - var id, idAttr = /\sid=["'](.+?)["']/.exec(attrs); - if (idAttr === null) { - id = idFromCurrentHeaders(self.currentHeaders); - attrs += ' id="' + id + '"'; - } else { - id = idAttr[1]; - } + var id = idFromCurrentHeaders(self.currentHeaders); self.anchors.push(id); - return '' + content + ''; + attrs = attrs.replace(/\sid=["'].+?["']/, ''); + return '' + content + ''; }); // collect anchors