From 3c2b165de19c19e544cfb8f5ef3dac8e66f4eecf Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Thu, 23 Jul 2015 09:35:03 +0100 Subject: [PATCH] chore(doc-gen): add processor to check for unbalanced code fences (backticks) See https://github.com/angular/angular/pull/3213/files#diff-da1eabc74e0bafaa56d2bfe4bc223b05R19 --- docs/docs-package/index.js | 2 +- .../processors/checkUnbalancedBackTicks.js | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 docs/docs-package/processors/checkUnbalancedBackTicks.js diff --git a/docs/docs-package/index.js b/docs/docs-package/index.js index 829cbe82a4..312841d329 100644 --- a/docs/docs-package/index.js +++ b/docs/docs-package/index.js @@ -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) { diff --git a/docs/docs-package/processors/checkUnbalancedBackTicks.js b/docs/docs-package/processors/checkUnbalancedBackTicks.js new file mode 100644 index 0000000000..2d359c7785 --- /dev/null +++ b/docs/docs-package/processors/checkUnbalancedBackTicks.js @@ -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); + } + } + }); + } + }; +}; \ No newline at end of file