mirror of
https://activitypub.software/TransFem-org/sfm-js
synced 2024-11-28 17:03:03 +00:00
Merge branch 'work-31' into develop
This commit is contained in:
commit
bf31395071
2 changed files with 23 additions and 1 deletions
|
@ -24,6 +24,15 @@ export function toString(node: MfmNode | MfmNode[]): string {
|
|||
}
|
||||
}
|
||||
|
||||
export function inspect(tree: MfmNode[], action: (node: MfmNode) => void): void {
|
||||
for (const node of tree) {
|
||||
action(node);
|
||||
if (node.children != null) {
|
||||
inspect(node.children, action);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
MfmNode,
|
||||
MfmBlock,
|
||||
|
|
15
test/main.ts
15
test/main.ts
|
@ -1,5 +1,5 @@
|
|||
import assert from 'assert';
|
||||
import { parse, parsePlain } from '../built/index';
|
||||
import { inspect, parse, parsePlain, toString } from '../built/index';
|
||||
import { createNode } from '../built/util';
|
||||
import {
|
||||
TEXT, CENTER, FN, UNI_EMOJI, MENTION, CUSTOM_EMOJI, HASHTAG, N_URL, BOLD, SMALL, ITALIC, STRIKE, QUOTE
|
||||
|
@ -401,3 +401,16 @@ https://github.com/syuilo/ai
|
|||
];
|
||||
assert.deepStrictEqual(parse(input), output);
|
||||
});
|
||||
|
||||
describe('inspect', () => {
|
||||
it('replace text', () => {
|
||||
const input = 'good morning [tada everynyan!]';
|
||||
const result = parse(input);
|
||||
inspect(result, node => {
|
||||
if (node.type == 'text') {
|
||||
node.props.text = node.props.text.replace(/good morning/g, 'hello');
|
||||
}
|
||||
});
|
||||
assert.strictEqual(toString(result), 'hello [tada everynyan!]');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue