Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion aio/tools/transforms/angular.io-package/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ module.exports = new Package('angular.io', [gitPackage, apiPackage, contentPacka
renderDocsProcessor.extraData.versionInfo = versionInfo;
})

.config(function(checkAnchorLinksProcessor) {
.config(function(checkAnchorLinksProcessor, linkInlineTagDef) {

// Fail the processing if there is an invalid link
linkInlineTagDef.failOnBadLink = true;

checkAnchorLinksProcessor.$enabled = true;
// since we encode the HTML to JSON we need to ensure that this processor runs before that encoding happens.
checkAnchorLinksProcessor.$runBefore = ['convertToJsonProcessor'];
Expand Down
14 changes: 10 additions & 4 deletions aio/tools/transforms/links-package/inline-tag-defs/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,29 @@ var INLINE_LINK = /(\S+)(?:\s+([\s\S]+))?/;
* @param {Function} docs error message
* @return {String} The html link information
*
* @property {boolean} relativeLinks Whether we expect the links to be relative to the originating doc
* @property {boolean} failOnBadLink Whether to throw an error (aborting the processing) if a link is invalid.
*/
module.exports = function linkInlineTagDef(getLinkInfo, createDocMessage, log) {
return {
name: 'link',
aliases: ['linkDocs'],
failOnBadLink: false,
description:
'Process inline link tags (of the form {@link some/uri Some Title}), replacing them with HTML anchors',
handler: function(doc, tagName, tagDescription) {
handler(doc, tagName, tagDescription) {

// Parse out the uri and title
return tagDescription.replace(INLINE_LINK, function(match, uri, title) {
return tagDescription.replace(INLINE_LINK, (match, uri, title) => {

var linkInfo = getLinkInfo(uri, title, doc);

if (!linkInfo.valid) {
log.warn(createDocMessage(linkInfo.error, doc));
const message = createDocMessage(linkInfo.error, doc);
if (this.failOnBadLink) {
throw new Error(message);
} else {
log.warn(message);
}
}

return '<a href=\'' + linkInfo.url + '\'>' + linkInfo.title + '</a>';
Expand Down