angular-cn/public/api-builder/docs-package/processors/checkUnbalancedBackTicks.js
Peter Bacon Darwin 3baf6c0561 refactor(checkUnbalancedTicks): split out convertBackticksToCodeBlocks to maintain cohesion
This improves upon changes made in 28a805733f6bd8b3a3394ea29c828c17b391c855
as part of #277
2015-10-17 19:11:53 -07:00

31 lines
998 B
JavaScript

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'],
$runAfter: ['inlineTagProcessor'],
$runBefore: ['writeFilesProcessor'],
$process: function(docs) {
_.forEach(docs, function(doc) {
if ( doc.renderedContent ) {
var matches = doc.renderedContent.match(BACKTICK_REGEX);
if (matches && matches.length % 2 !== 0) {
doc.unbalancedBackTicks = true;
log.warn(createDocMessage('checkUnbalancedBackTicks processor: unbalanced backticks found in rendered content', doc));
log.warn(doc.renderedContent);
}
}
});
}
};
};