Skip to content

Commit 3c2b165

Browse files
chore(doc-gen): add processor to check for unbalanced code fences (backticks)
See https://github.com/angular/angular/pull/3213/files#diff-da1eabc74e0bafaa56d2bfe4bc223b05R19
1 parent 76f63bc commit 3c2b165

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

docs/docs-package/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = new Package('angular-v2-docs', [jsdocPackage, nunjucksPackage,
1818
.processor(require('./processors/generateNavigationDoc'))
1919
.processor(require('./processors/extractTitleFromGuides'))
2020
.processor(require('./processors/createOverviewDump'))
21-
21+
.processor(require('./processors/checkUnbalancedBackTicks'))
2222

2323
// Configure the log service
2424
.config(function(log) {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
var _ = require('lodash');
2+
3+
/**
4+
* @dgProcessor checkUnbalancedBackTicks
5+
* @description
6+
* Searches the rendered content for an odd number of (```) backticks,
7+
* which would indicate an unbalanced pair and potentially a typo in the
8+
* source content.
9+
*/
10+
module.exports = function checkUnbalancedBackTicks(log, createDocMessage) {
11+
12+
var BACKTICK_REGEX = /^ *```/gm;
13+
14+
return {
15+
$runAfter: ['checkAnchorLinksProcessor'],
16+
$process: function(docs) {
17+
_.forEach(docs, function(doc) {
18+
if ( doc.renderedContent ) {
19+
var matches = doc.renderedContent.match(BACKTICK_REGEX);
20+
if (matches && matches.length % 2 !== 0) {
21+
log.warn(createDocMessage('checkUnbalancedBackTicks processor: unbalanced backticks found in rendered content', doc));
22+
console.log(doc.renderedContent);
23+
}
24+
}
25+
});
26+
}
27+
};
28+
};

0 commit comments

Comments
 (0)