refactor(docs-infra): refactors checkUnbalancedBackTicks
(#37065)
This commit removes the dependency on the `lodash` module and refactors the `checkUnbalancedBackTicks` method. PR Close #37065
This commit is contained in:
parent
05f1df3224
commit
03afa36334
@ -1,5 +1,3 @@
|
|||||||
var _ = require('lodash');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dgProcessor checkUnbalancedBackTicks
|
* @dgProcessor checkUnbalancedBackTicks
|
||||||
* @description
|
* @description
|
||||||
@ -9,25 +7,28 @@ var _ = require('lodash');
|
|||||||
*/
|
*/
|
||||||
module.exports = function checkUnbalancedBackTicks(log, createDocMessage) {
|
module.exports = function checkUnbalancedBackTicks(log, createDocMessage) {
|
||||||
|
|
||||||
var BACKTICK_REGEX = /^ *```/gm;
|
const BACKTICK_REGEX = /^ *```/gm;
|
||||||
|
const UNBALANCED_BACKTICK_WARNING = 'checkUnbalancedBackTicks processor: unbalanced backticks found in rendered content';
|
||||||
|
|
||||||
return {
|
return {
|
||||||
// $runAfter: ['checkAnchorLinksProcessor'],
|
|
||||||
$runAfter: ['inlineTagProcessor'],
|
$runAfter: ['inlineTagProcessor'],
|
||||||
$runBefore: ['writeFilesProcessor'],
|
$runBefore: ['writeFilesProcessor'],
|
||||||
$process: function(docs) {
|
$process: function(docs) {
|
||||||
_.forEach(docs, function(doc) {
|
docs
|
||||||
if (doc.renderedContent) {
|
.forEach(doc => setUnbalancedBackTicks(doc));
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function setUnbalancedBackTicks(doc) {
|
||||||
|
if (!doc.renderedContent) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const matches = doc.renderedContent.match(BACKTICK_REGEX);
|
||||||
|
if (matches && matches.length % 2 !== 0) {
|
||||||
|
doc.unbalancedBackTicks = true;
|
||||||
|
log.warn(createDocMessage(UNBALANCED_BACKTICK_WARNING, doc));
|
||||||
|
log.warn(doc.renderedContent);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
Loading…
x
Reference in New Issue
Block a user