Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
docs: properly format anchor names and hrefs (#11648)
Browse files Browse the repository at this point in the history
anchor names should not include any path info
hrefs need to include the baseURL in addition to the path

Fixes #11644. Relates to #11634. Relates to #11285.
  • Loading branch information
Splaktar authored and jelbourn committed Feb 23, 2019
1 parent d3773a5 commit 163b762
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
13 changes: 10 additions & 3 deletions docs/app/js/anchor.js
Expand Up @@ -25,7 +25,7 @@
return;
}

var anchorEl = $compile('<a class="docs-anchor" ng-href="{{ name }}" name="{{ name }}"></a>')(scope);
var anchorEl = $compile('<a class="docs-anchor" ng-href="{{ href }}" name="{{ name }}"></a>')(scope);

// Wrap contents inside of the anchor element.
anchorEl.append(element.contents());
Expand All @@ -40,16 +40,23 @@
* Creates URL from the text content of the element and writes it into the scope.
*/
function createContentURL() {
var path = scope.$root.$location ? scope.$root.$location.path() : '';
var path = '';
var name = element.text();
// Use $window.location.pathname to get the path with the baseURL included.
// $location.path() does not include the baseURL. This is important to support how the docs
// are deployed with baseURLs like /latest, /HEAD, /1.1.13, etc.
if (scope.$root.$window && scope.$root.$window.location) {
path = scope.$root.$window.location.pathname;
}
name = name
.trim() // Trim text due to browsers extra whitespace.
.replace(/'/g, '') // Transform apostrophes words to a single one.
.replace(unsafeCharRegex, '-') // Replace unsafe chars with a dash symbol.
.replace(/-{2,}/g, '-') // Remove repeating dash symbols.
.replace(/^-|-$/g, '') // Remove preceding or ending dashes.
.toLowerCase(); // Link should be lower-case for accessible URL.
scope.name = path + '#' + name;
scope.name = name;
scope.href = path + '#' + name;
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions docs/app/js/app.js
Expand Up @@ -148,9 +148,9 @@ function(SERVICES, COMPONENTS, DEMOS, PAGES,
AngularyticsProvider.setEventHandlers(['GoogleUniversal']);
}])

.run(['$rootScope', '$location', 'Angularytics', function($rootScope, $location, Angularytics) {
.run(['$rootScope', '$window', 'Angularytics', function($rootScope, $window, Angularytics) {
Angularytics.init();
$rootScope.$location = $location;
$rootScope.$window = $window;
}])

.factory('menu', [
Expand Down Expand Up @@ -453,7 +453,7 @@ function(SERVICES, COMPONENTS, DEMOS, PAGES, $location, $rootScope, $http, $wind
type: "link"
};

if (path == '/') {
if (path === '/') {
self.selectSection(introLink);
self.selectPage(introLink, introLink);
return;
Expand Down

0 comments on commit 163b762

Please sign in to comment.