2015-09-16 02:21:55 -04:00
|
|
|
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;
|
2015-10-16 12:03:54 -04:00
|
|
|
|
2015-09-16 02:21:55 -04:00
|
|
|
return {
|
2015-10-16 12:03:54 -04:00
|
|
|
// $runAfter: ['checkAnchorLinksProcessor'],
|
|
|
|
$runAfter: ['inlineTagProcessor'],
|
|
|
|
$runBefore: ['writeFilesProcessor'],
|
2015-09-16 02:21:55 -04:00
|
|
|
$process: function(docs) {
|
|
|
|
_.forEach(docs, function(doc) {
|
|
|
|
if ( doc.renderedContent ) {
|
|
|
|
var matches = doc.renderedContent.match(BACKTICK_REGEX);
|
|
|
|
if (matches && matches.length % 2 !== 0) {
|
2015-10-17 03:45:56 -04:00
|
|
|
doc.unbalancedBackTicks = true;
|
2015-09-16 02:21:55 -04:00
|
|
|
log.warn(createDocMessage('checkUnbalancedBackTicks processor: unbalanced backticks found in rendered content', doc));
|
2015-10-17 03:45:56 -04:00
|
|
|
log.warn(doc.renderedContent);
|
2015-09-16 02:21:55 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|