File tree 2 files changed +30
-0
lines changed
2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ node cat.js < ..\Test.json
Original file line number Diff line number Diff line change
1
+ var assert = require ( 'assert' ) ;
2
+
3
+ process . stdin . setEncoding ( 'utf8' ) ;
4
+ process . stdout . setEncoding ( 'utf8' ) ;
5
+
6
+ var input = '' ;
7
+
8
+ process . stdin . on ( 'data' , function ( data ) { input += data ; } ) ;
9
+ process . stdin . on ( 'end' , function ( ) { handleInput ( ) ; } ) ;
10
+ process . stdin . resume ( ) ;
11
+
12
+ function handleInput ( ) {
13
+ var root = JSON . parse ( input ) ;
14
+ assert . equal ( root . shift ( ) , 'text' ) ;
15
+
16
+ root . forEach ( function ( block ) {
17
+ var blockType = block . shift ( ) ;
18
+ var blockAttr = block . shift ( ) ;
19
+
20
+ block . forEach ( function ( span ) {
21
+ var spanType = span . shift ( ) ;
22
+ assert ( span . length , 1 ) ;
23
+ var text = span [ 0 ] ;
24
+ process . stdout . write ( text ) ;
25
+ } ) ;
26
+
27
+ process . stdout . write ( '\n\n' ) ;
28
+ } ) ;
29
+ } ;
You can’t perform that action at this time.
0 commit comments