blob: c16dfd633ee6ad23548f65ad047ffc178b052133 [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001'use strict'
2
3const walk = ( node, parent, cb ) => {
4 cb( node, parent )
5
6 if( Array.isArray( node.children ) )
7 node.children.forEach( child => walk( child, node, cb ) )
8}
9
10const data = {
11 name: 'div',
12 attribs: {
13 id: 'container',
14 class: 'message'
15 },
16 children: [
17 {
18 name: 'strong',
19 attribs: {
20 class: 'message'
21 },
22 children: [
23 { text: 'Hello' }
24 ]
25 },
26 { text: ', World!' }
27 ]
28}
29
30walk( data, null, ( node, parent ) => {
31 if( parent ) node.parent = parent
32})
33
34module.exports = [ data ]