File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ < textarea cols ="50 " rows ="5 "> < p > Hello, world!</ p > </ textarea >
2
+ < pre > < code > </ code > </ pre >
3
+ < script src ="https://unpkg.com/react@16/umd/react.production.min.js "> </ script >
4
+ < script src ="../dist/html-react-parser.min.js "> </ script >
5
+ < script >
6
+ var code = document . querySelector ( 'code' ) ;
7
+ var textarea = document . querySelector ( 'textarea' ) ;
8
+
9
+ function renderOutput ( event ) {
10
+ cache = [ ] ;
11
+ code . innerText = JSON . stringify (
12
+ window . HTMLReactParser ( event . target . value ) ,
13
+ replacer ,
14
+ 2
15
+ ) ;
16
+ }
17
+
18
+ textarea . addEventListener ( 'input' , renderOutput ) ;
19
+ renderOutput ( { target : textarea } ) ;
20
+
21
+ /**
22
+ * @see {@link https://stackoverflow.com/questions/11616630/json-stringify-avoid-typeerror-converting-circular-structure-to-json }
23
+ */
24
+ var cache ;
25
+ function replacer ( key , value ) {
26
+ if ( typeof value === 'object' && value !== null ) {
27
+ if ( cache . indexOf ( value ) !== - 1 ) {
28
+ // duplicate reference found
29
+ return '[Circular]' ;
30
+ }
31
+ // store value in our collection
32
+ cache . push ( value ) ;
33
+ }
34
+ return value ;
35
+ }
36
+ </ script >
You can’t perform that action at this time.
0 commit comments