File tree Expand file tree Collapse file tree 2 files changed +22
-5
lines changed Expand file tree Collapse file tree 2 files changed +22
-5
lines changed Original file line number Diff line number Diff line change
1
+ import { sanitize } from "dompurify" ;
2
+
3
+ const input = document . querySelector ( '[name="input"]' ) ;
4
+ const output = document . querySelector ( ".output" ) ;
5
+ const buttons = document . querySelectorAll ( "nav button" ) ;
6
+ input . addEventListener ( "input" , ( ) => {
7
+ const clean = sanitize ( input . value , {
8
+ FORBID_ATTR : [ "width" , "height" , "style" ] ,
9
+ FORBID_TAGS : [ "style" ] ,
10
+ } ) ;
11
+ output . innerHTML = clean . replace ( / \n / g, "<br>" ) ;
12
+ } ) ;
13
+
14
+ // trigger an input even on page load
15
+ input . dispatchEvent ( new Event ( "input" ) ) ;
16
+
17
+ buttons . forEach ( ( button ) =>
18
+ button . addEventListener ( "click" , ( e ) => {
19
+ alert ( e . currentTarget . textContent ) ;
20
+ } )
21
+ ) ;
Original file line number Diff line number Diff line change @@ -4,11 +4,7 @@ const input = document.querySelector('[name="input"]');
4
4
const output = document . querySelector ( '.output' ) ;
5
5
const buttons = document . querySelectorAll ( 'nav button' ) ;
6
6
input . addEventListener ( 'input' , ( ) => {
7
- const clean = sanitize ( input . value , {
8
- FORBID_ATTR : [ 'width' , 'height' , 'style' ] ,
9
- FORBID_TAGS : [ 'style' ] ,
10
- } ) ;
11
- output . innerHTML = clean . replace ( / \n / g, '<br>' ) ;
7
+ output . innerHTML = input . value . replace ( / \n / g, '<br>' ) ;
12
8
} ) ;
13
9
14
10
// trigger an input even on page load
You can’t perform that action at this time.
0 commit comments