fix #7873 - links to footnotes removed on paste
[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.searchTag(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
35         var ar = Array.from(node.childNodes);
36         for (var i = 0; i < ar.length; i++) {
37             node.removeChild(ar[i]);
38             // what if we need to walk these???
39             node.parentNode.insertBefore(ar[i], node);
40         }
41         // now what about this?
42         // <p> &nbsp; </p>
43         
44         // double BR.
45         node.parentNode.insertBefore(node.ownerDocument.createElement('BR'), node);
46         node.parentNode.insertBefore(node.ownerDocument.createElement('BR'), node);
47         node.parentNode.removeChild(node);
48         
49         return false;
50
51     }
52     
53 });