mirror of
https://github.com/LukeHagar/unicorn-utterances.git
synced 2025-12-10 04:22:06 +00:00
Migrate to parent unist package
This commit is contained in:
@@ -1,31 +1,22 @@
|
||||
const flatFilter = (ast, truthyFunc) => {
|
||||
if (!ast) return [];
|
||||
if (truthyFunc(ast)) return [ast];
|
||||
if (!ast.children) return [];
|
||||
let acceptedChildren = [];
|
||||
for (const child of ast.children) {
|
||||
const flatFilterResult = flatFilter(child, truthyFunc);
|
||||
if (flatFilterResult && flatFilterResult.length) {
|
||||
// Take array results and push to the returned array to flatten it
|
||||
flatFilterResult.forEach(flatFilterResultItem => {
|
||||
acceptedChildren.push(flatFilterResultItem);
|
||||
});
|
||||
}
|
||||
}
|
||||
return acceptedChildren;
|
||||
};
|
||||
const flatFilter = require("unist-util-flat-filter");
|
||||
|
||||
const addVideo = ({ markdownAST, actions, markdownNode, ...props }) => {
|
||||
const addInlineCount = ({ markdownAST, actions, markdownNode, ...props }) => {
|
||||
const { createNodeField } = actions;
|
||||
const inlineCodeAST = flatFilter(
|
||||
markdownAST,
|
||||
node => node.type === "inlineCode"
|
||||
);
|
||||
const inlineWords = inlineCodeAST.reduce((numberOfInline, inlineCodeNode) => {
|
||||
const { value } = inlineCodeNode;
|
||||
const words = value.split(/\b/g);
|
||||
return numberOfInline + words.length;
|
||||
}, 0);
|
||||
let inlineWords = 0;
|
||||
if (inlineCodeAST && inlineCodeAST.children) {
|
||||
inlineWords = inlineCodeAST.children.reduce(
|
||||
(numberOfInline, inlineCodeNode) => {
|
||||
const { value } = inlineCodeNode;
|
||||
const words = value.split(/\b/g);
|
||||
return numberOfInline + words.length;
|
||||
},
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
createNodeField({
|
||||
name: `inlineCount`,
|
||||
@@ -34,4 +25,4 @@ const addVideo = ({ markdownAST, actions, markdownNode, ...props }) => {
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = addVideo;
|
||||
module.exports = addInlineCount;
|
||||
|
||||
Reference in New Issue
Block a user