1
- import { visit , SKIP } from "unist-util-visit" ;
2
-
3
- /**
4
- * Perform the redaction transform by wrapping text nodes inside delete nodes
5
- *
6
- * @param node - tree to transform
7
- */
8
- function redactTransformImpl ( node , index , parent ) {
9
- console . log ( "Found redacted" , node . type ) ;
10
- visit ( node , "text" , ( child , childIndex , childParent ) => {
11
- const maybeParent = childParent || parent ;
12
- const maybeIndex = childIndex || index ;
13
- if ( maybeParent ) {
14
- maybeParent . children [ maybeIndex ] = {
15
- type : "delete" ,
16
- children : [ child ] ,
17
- } ;
18
- }
19
- return SKIP ;
20
- } ) ;
21
- return SKIP ;
22
- }
1
+ import { visit , SKIP , EXIT } from "unist-util-visit" ;
23
2
24
3
/**
25
4
* Locate `redacted` nodes, and redact their text children (recursively)
@@ -33,9 +12,17 @@ function redactTransform(node) {
33
12
child . class . split ( / \s / ) . some ( ( class_ ) => class_ === "redacted" )
34
13
) ;
35
14
} ;
36
- visit ( node , test , ( child , index , parent ) =>
37
- redactTransformImpl ( child , index , parent ) ,
38
- ) ;
15
+ visit ( node , test , ( child , index , parent ) => {
16
+ // Wrap any child text nodes
17
+ visit ( child , "text" , ( textChild , textIndex , textParent ) => {
18
+ ( textParent ?? parent ) . children [ textParent ? textIndex : index ] = {
19
+ type : "delete" ,
20
+ children : [ textChild ] ,
21
+ } ;
22
+ return SKIP ;
23
+ } ) ;
24
+ return SKIP ;
25
+ } ) ;
39
26
}
40
27
41
28
const plugin = {
0 commit comments