build(aio): fail the doc-gen if there is an invalid `{@link ...}` tag
This fail behaviour is only turned on for `yarn docs`; in `yarn docs-watch` you only receive a warning. This is because you can get false errors when watching since we don't parse all the docs in that case.
This commit is contained in:
parent
dc7d24267d
commit
f5335d17ec
|
@ -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'];
|
||||
|
|
|
@ -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>';
|
||||
|
|
Loading…
Reference in New Issue