mirror of
https://activitypub.software/TransFem-org/Sharkey.git
synced 2024-12-15 09:15:44 +01:00
Refactor getTextCount (#3553)
Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com>
This commit is contained in:
parent
17baf8770a
commit
34235d4d44
1 changed files with 3 additions and 9 deletions
|
@ -10,15 +10,9 @@ import { toUnicode } from 'punycode';
|
||||||
import syntaxHighlight from '../../../../../mfm/syntax-highlight';
|
import syntaxHighlight from '../../../../../mfm/syntax-highlight';
|
||||||
|
|
||||||
function getTextCount(tokens: Node[]): number {
|
function getTextCount(tokens: Node[]): number {
|
||||||
let count = 0;
|
const rootCount = sum(tokens.filter(x => x.name === 'text').map(x => length(x.props.text)));
|
||||||
const extract = (tokens: Node[]) => {
|
const childrenCount = sum(tokens.filter(x => x.children).map(x => getTextCount(x.children)));
|
||||||
count += sum(tokens.filter(x => x.name === 'text').map(x => length(x.props.text)));
|
return rootCount + childrenCount;
|
||||||
tokens.filter(x => x.children).forEach(x => {
|
|
||||||
extract(x.children);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
extract(tokens);
|
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getChildrenCount(tokens: Node[]): number {
|
function getChildrenCount(tokens: Node[]): number {
|
||||||
|
|
Loading…
Reference in a new issue