| 1 | <!DOCTYPE html> |
|---|
| 2 | <html> |
|---|
| 3 | <head> |
|---|
| 4 | <title>CKEDITOR.htmlParser.filter</title> |
|---|
| 5 | <script src="CKEditor/trunk/ckeditor_source.js"></script> |
|---|
| 6 | <script> |
|---|
| 7 | function htmlParse( htmlString, filter ) |
|---|
| 8 | { |
|---|
| 9 | var writer = new CKEDITOR.htmlParser.basicWriter(), |
|---|
| 10 | fragment = CKEDITOR.htmlParser.fragment.fromHtml( htmlString ); |
|---|
| 11 | fragment.writeHtml( writer, filter ); |
|---|
| 12 | return writer.getHtml(); |
|---|
| 13 | } |
|---|
| 14 | |
|---|
| 15 | function areEqual( expected, actual ) |
|---|
| 16 | { |
|---|
| 17 | alert( 'Result: ' + (expected == actual) + '.\nExpected: ' + expected + '.\nActual: ' + actual ); |
|---|
| 18 | } |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | var filter = new CKEDITOR.htmlParser.filter(); |
|---|
| 22 | filter.addRules( { |
|---|
| 23 | elementNames : |
|---|
| 24 | [ |
|---|
| 25 | [ ( /^p$/ ), '' ], |
|---|
| 26 | [ ( /^sth:/ ), '' ] |
|---|
| 27 | ] |
|---|
| 28 | } ); |
|---|
| 29 | areEqual( '<p>a</p>', htmlParse( '<sth:p>a</sth:p>', filter ) ); // -> true |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | var filter = new CKEDITOR.htmlParser.filter(); |
|---|
| 33 | filter.addRules( { |
|---|
| 34 | attributeNames : |
|---|
| 35 | [ |
|---|
| 36 | [ ( /^title$/ ), '' ], |
|---|
| 37 | [ ( /^sth-/ ), '' ] |
|---|
| 38 | ] |
|---|
| 39 | } ); |
|---|
| 40 | areEqual( '<p title="abc"></p>', htmlParse( '<p sth-title="abc"></p>', filter ) ); // -> false |
|---|
| 41 | </script> |
|---|
| 42 | </head> |
|---|
| 43 | <body> |
|---|
| 44 | </body> |
|---|
| 45 | </html> |
|---|