Skip to content

Commit c7bd463

Browse files
fix: refactor for less redundant with same logic for code blocks
1 parent 4b4b5b3 commit c7bd463

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

Diff for: src/Block.tsx

+12-19
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,23 @@ const voidTypes = ['image'];
1616
*/
1717
const augmentProps = (content: Node) => {
1818
const { children: childrenNodes, type, ...props } = content;
19-
const getPlainText = (children: typeof childrenNodes): string => {
20-
return children.reduce((currentPlainText, node) => {
21-
if (node.type === 'text') {
22-
return currentPlainText.concat(node.text);
23-
}
2419

25-
if (node.type === 'link') {
26-
return currentPlainText.concat(getPlainText(node.children));
27-
}
28-
29-
return currentPlainText;
30-
}, '');
31-
};
32-
33-
if (type === 'code') {
20+
if (type === 'code' || type === 'heading') {
3421
// Builds a plain text string from an array of nodes, regardless of links or modifiers
22+
const getPlainText = (children: typeof childrenNodes): string => {
23+
return children.reduce((currentPlainText, node) => {
24+
if (node.type === 'text') {
25+
return currentPlainText.concat(node.text);
26+
}
3527

36-
return {
37-
...props,
38-
plainText: getPlainText(content.children),
28+
if (node.type === 'link') {
29+
return currentPlainText.concat(getPlainText(node.children));
30+
}
31+
32+
return currentPlainText;
33+
}, '');
3934
};
40-
}
4135

42-
if (type === 'heading') {
4336
return {
4437
...props,
4538
plainText: getPlainText(content.children),

0 commit comments

Comments
 (0)