mirror of
https://github.com/hotomoe/hotomoe
synced 2024-12-12 21:58:12 +09:00
Refactor getTextCount (#3553)
Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com>
This commit is contained in:
parent
17baf8770a
commit
34235d4d44
@ -10,15 +10,9 @@ import { toUnicode } from 'punycode';
|
||||
import syntaxHighlight from '../../../../../mfm/syntax-highlight';
|
||||
|
||||
function getTextCount(tokens: Node[]): number {
|
||||
let count = 0;
|
||||
const extract = (tokens: Node[]) => {
|
||||
count += sum(tokens.filter(x => x.name === 'text').map(x => length(x.props.text)));
|
||||
tokens.filter(x => x.children).forEach(x => {
|
||||
extract(x.children);
|
||||
});
|
||||
};
|
||||
extract(tokens);
|
||||
return count;
|
||||
const rootCount = sum(tokens.filter(x => x.name === 'text').map(x => length(x.props.text)));
|
||||
const childrenCount = sum(tokens.filter(x => x.children).map(x => getTextCount(x.children)));
|
||||
return rootCount + childrenCount;
|
||||
}
|
||||
|
||||
function getChildrenCount(tokens: Node[]): number {
|
||||
|
Loading…
Reference in New Issue
Block a user