chore(doc-gen): add processor to check for unbalanced code fences (backticks)

See https://github.com/angular/angular/pull/3213/files#diff-da1eabc74e0bafaa56d2bfe4bc223b05R19
This commit is contained in:
Peter Bacon Darwin 2015-07-23 09:35:03 +01:00
parent 76f63bc6a5
commit 3c2b165de1
2 changed files with 29 additions and 1 deletions

View File

@ -18,7 +18,7 @@ module.exports = new Package('angular-v2-docs', [jsdocPackage, nunjucksPackage,
.processor(require('./processors/generateNavigationDoc'))
.processor(require('./processors/extractTitleFromGuides'))
.processor(require('./processors/createOverviewDump'))
.processor(require('./processors/checkUnbalancedBackTicks'))
// Configure the log service
.config(function(log) {

View File

@ -0,0 +1,28 @@
var _ = require('lodash');
/**
* @dgProcessor checkUnbalancedBackTicks
* @description
* Searches the rendered content for an odd number of (```) backticks,
* which would indicate an unbalanced pair and potentially a typo in the
* source content.
*/
module.exports = function checkUnbalancedBackTicks(log, createDocMessage) {
var BACKTICK_REGEX = /^ *```/gm;
return {
$runAfter: ['checkAnchorLinksProcessor'],
$process: function(docs) {
_.forEach(docs, function(doc) {
if ( doc.renderedContent ) {
var matches = doc.renderedContent.match(BACKTICK_REGEX);
if (matches && matches.length % 2 !== 0) {
log.warn(createDocMessage('checkUnbalancedBackTicks processor: unbalanced backticks found in rendered content', doc));
console.log(doc.renderedContent);
}
}
});
}
};
};