more styling
[roojs1] / Roo / htmleditor / FilterParagraph.js
1 /**
2  * @class Roo.htmleditor.FilterParagraph
3  * paragraphs cause a nightmare for shared content - this filter is designed to be called ? at various points when editing
4  * like on 'push' to remove the <p> tags and replace them with line breaks.
5  * @constructor
6  * Run a new Paragraph Filter
7  * @param {Object} config Configuration options
8  */
9
10 Roo.htmleditor.FilterParagraph = function(cfg)
11 {
12     // no need to apply config.
13     this.walk(cfg.node);
14 }
15
16 Roo.extend(Roo.htmleditor.FilterParagraph, Roo.htmleditor.Filter,
17 {
18     
19      
20     tag : 'P',
21     
22      
23     replaceTag : function(node)
24     {
25         
26         if (node.childNodes.length == 1 &&
27             node.childNodes[0].nodeType == 3 &&
28             node.childNodes[0].textContent.trim().length < 1
29             ) {
30             // remove and replace with '<BR>';
31             node.parentNode.replaceChild(node.ownerDocument.createElement('BR'),node);
32             return false; // no need to walk..
33         }
34         var ar = Array.from(node.childNodes);
35         for (var i = 0; i < ar.length; i++) {
36             node.removeChild(ar[i]);
37             // what if we need to walk these???
38             node.parentNode.insertBefore(ar[i], node);
39         }
40         // now what about this?
41         // <p> &nbsp; </p>
42         
43         // double BR.
44         node.parentNode.insertBefore(node.ownerDocument.createElement('BR'), node);
45         node.parentNode.insertBefore(node.ownerDocument.createElement('BR'), node);
46         node.parentNode.removeChild(node);
47         
48         return false;
49
50     }
51     
52 });