1 |
1 /* global tinymce, tinyMCEPreInit, QTags, setUserSetting */ |
2 var switchEditors = { |
2 |
3 |
3 window.switchEditors = { |
4 switchto: function(el) { |
4 |
5 var aid = el.id, l = aid.length, id = aid.substr(0, l - 5), mode = aid.substr(l - 4); |
5 switchto: function( el ) { |
6 |
6 var aid = el.id, |
7 this.go(id, mode); |
7 l = aid.length, |
8 }, |
8 id = aid.substr( 0, l - 5 ), |
9 |
9 mode = aid.substr( l - 4 ); |
10 go: function(id, mode) { // mode can be 'html', 'tmce', or 'toggle'; 'html' is used for the "Text" editor tab. |
10 |
|
11 this.go( id, mode ); |
|
12 }, |
|
13 |
|
14 // mode can be 'html', 'tmce', or 'toggle'; 'html' is used for the 'Text' editor tab. |
|
15 go: function( id, mode ) { |
|
16 var t = this, ed, wrap_id, txtarea_el, iframe, editorHeight, toolbarHeight, |
|
17 DOM = tinymce.DOM; //DOMUtils outside the editor iframe |
|
18 |
11 id = id || 'content'; |
19 id = id || 'content'; |
12 mode = mode || 'toggle'; |
20 mode = mode || 'toggle'; |
13 |
21 |
14 var t = this, ed = tinyMCE.get(id), wrap_id, txtarea_el, dom = tinymce.DOM; |
22 ed = tinymce.get( id ); |
15 |
23 wrap_id = 'wp-' + id + '-wrap'; |
16 wrap_id = 'wp-'+id+'-wrap'; |
24 txtarea_el = DOM.get( id ); |
17 txtarea_el = dom.get(id); |
25 |
18 |
26 if ( 'toggle' === mode ) { |
19 if ( 'toggle' == mode ) { |
27 if ( ed && ! ed.isHidden() ) { |
20 if ( ed && !ed.isHidden() ) |
|
21 mode = 'html'; |
28 mode = 'html'; |
22 else |
29 } else { |
23 mode = 'tmce'; |
30 mode = 'tmce'; |
24 } |
31 } |
25 |
32 } |
26 if ( 'tmce' == mode || 'tinymce' == mode ) { |
33 |
27 if ( ed && ! ed.isHidden() ) |
34 function getToolbarHeight() { |
|
35 var node = DOM.select( '.mce-toolbar-grp', ed.getContainer() )[0], |
|
36 height = node && node.clientHeight; |
|
37 |
|
38 if ( height && height > 10 && height < 200 ) { |
|
39 return parseInt( height, 10 ); |
|
40 } |
|
41 |
|
42 return 30; |
|
43 } |
|
44 |
|
45 if ( 'tmce' === mode || 'tinymce' === mode ) { |
|
46 if ( ed && ! ed.isHidden() ) { |
28 return false; |
47 return false; |
29 |
48 } |
30 if ( typeof(QTags) != 'undefined' ) |
49 |
31 QTags.closeAllTags(id); |
50 if ( typeof( QTags ) !== 'undefined' ) { |
32 |
51 QTags.closeAllTags( id ); |
33 if ( tinyMCEPreInit.mceInit[id] && tinyMCEPreInit.mceInit[id].wpautop ) |
52 } |
|
53 |
|
54 editorHeight = txtarea_el ? parseInt( txtarea_el.style.height, 10 ) : 0; |
|
55 |
|
56 if ( tinyMCEPreInit.mceInit[ id ] && tinyMCEPreInit.mceInit[ id ].wpautop ) { |
34 txtarea_el.value = t.wpautop( txtarea_el.value ); |
57 txtarea_el.value = t.wpautop( txtarea_el.value ); |
|
58 } |
35 |
59 |
36 if ( ed ) { |
60 if ( ed ) { |
37 ed.show(); |
61 ed.show(); |
|
62 |
|
63 // No point resizing the iframe in iOS |
|
64 if ( ! tinymce.Env.iOS && editorHeight ) { |
|
65 toolbarHeight = getToolbarHeight(); |
|
66 editorHeight = editorHeight - toolbarHeight + 14; |
|
67 |
|
68 // height cannot be under 50 or over 5000 |
|
69 if ( editorHeight > 50 && editorHeight < 5000 ) { |
|
70 ed.theme.resizeTo( null, editorHeight ); |
|
71 } |
|
72 } |
38 } else { |
73 } else { |
39 ed = new tinymce.Editor(id, tinyMCEPreInit.mceInit[id]); |
74 tinymce.init( tinyMCEPreInit.mceInit[id] ); |
40 ed.render(); |
75 } |
41 } |
76 |
42 |
77 DOM.removeClass( wrap_id, 'html-active' ); |
43 dom.removeClass(wrap_id, 'html-active'); |
78 DOM.addClass( wrap_id, 'tmce-active' ); |
44 dom.addClass(wrap_id, 'tmce-active'); |
79 DOM.setAttrib( txtarea_el, 'aria-hidden', true ); |
45 setUserSetting('editor', 'tinymce'); |
80 setUserSetting( 'editor', 'tinymce' ); |
46 |
81 |
47 } else if ( 'html' == mode ) { |
82 } else if ( 'html' === mode ) { |
48 |
83 |
49 if ( ed && ed.isHidden() ) |
84 if ( ed && ed.isHidden() ) { |
50 return false; |
85 return false; |
|
86 } |
51 |
87 |
52 if ( ed ) { |
88 if ( ed ) { |
|
89 if ( ! tinymce.Env.iOS ) { |
|
90 iframe = DOM.get( id + '_ifr' ); |
|
91 editorHeight = iframe ? parseInt( iframe.style.height, 10 ) : 0; |
|
92 |
|
93 if ( editorHeight ) { |
|
94 toolbarHeight = getToolbarHeight(); |
|
95 editorHeight = editorHeight + toolbarHeight - 14; |
|
96 |
|
97 // height cannot be under 50 or over 5000 |
|
98 if ( editorHeight > 50 && editorHeight < 5000 ) { |
|
99 txtarea_el.style.height = editorHeight + 'px'; |
|
100 } |
|
101 } |
|
102 } |
|
103 |
53 ed.hide(); |
104 ed.hide(); |
54 } else { |
105 } else { |
55 // The TinyMCE instance doesn't exist, run the content through "pre_wpautop()" and show the textarea |
106 // The TinyMCE instance doesn't exist, run the content through 'pre_wpautop()' and show the textarea |
56 if ( tinyMCEPreInit.mceInit[id] && tinyMCEPreInit.mceInit[id].wpautop ) |
107 if ( tinyMCEPreInit.mceInit[ id ] && tinyMCEPreInit.mceInit[ id ].wpautop ) { |
57 txtarea_el.value = t.pre_wpautop( txtarea_el.value ); |
108 txtarea_el.value = t.pre_wpautop( txtarea_el.value ); |
58 |
109 } |
59 dom.setStyles(txtarea_el, {'display': '', 'visibility': ''}); |
110 |
60 } |
111 DOM.setStyles( txtarea_el, {'display': '', 'visibility': ''} ); |
61 |
112 } |
62 dom.removeClass(wrap_id, 'tmce-active'); |
113 |
63 dom.addClass(wrap_id, 'html-active'); |
114 DOM.removeClass( wrap_id, 'tmce-active' ); |
64 setUserSetting('editor', 'html'); |
115 DOM.addClass( wrap_id, 'html-active' ); |
|
116 DOM.setAttrib( txtarea_el, 'aria-hidden', false ); |
|
117 setUserSetting( 'editor', 'html' ); |
65 } |
118 } |
66 return false; |
119 return false; |
67 }, |
120 }, |
68 |
121 |
69 _wp_Nop : function(content) { |
122 _wp_Nop: function( content ) { |
70 var blocklist1, blocklist2, preserve_linebreaks = false, preserve_br = false; |
123 var blocklist1, blocklist2, |
|
124 preserve_linebreaks = false, |
|
125 preserve_br = false; |
71 |
126 |
72 // Protect pre|script tags |
127 // Protect pre|script tags |
73 if ( content.indexOf('<pre') != -1 || content.indexOf('<script') != -1 ) { |
128 if ( content.indexOf( '<pre' ) !== -1 || content.indexOf( '<script' ) !== -1 ) { |
74 preserve_linebreaks = true; |
129 preserve_linebreaks = true; |
75 content = content.replace(/<(pre|script)[^>]*>[\s\S]+?<\/\1>/g, function(a) { |
130 content = content.replace( /<(pre|script)[^>]*>[\s\S]+?<\/\1>/g, function( a ) { |
76 a = a.replace(/<br ?\/?>(\r\n|\n)?/g, '<wp-temp-lb>'); |
131 a = a.replace( /<br ?\/?>(\r\n|\n)?/g, '<wp-line-break>' ); |
77 return a.replace(/<\/?p( [^>]*)?>(\r\n|\n)?/g, '<wp-temp-lb>'); |
132 a = a.replace( /<\/?p( [^>]*)?>(\r\n|\n)?/g, '<wp-line-break>' ); |
|
133 return a.replace( /\r?\n/g, '<wp-line-break>' ); |
78 }); |
134 }); |
79 } |
135 } |
80 |
136 |
81 // keep <br> tags inside captions and remove line breaks |
137 // keep <br> tags inside captions and remove line breaks |
82 if ( content.indexOf('[caption') != -1 ) { |
138 if ( content.indexOf( '[caption' ) !== -1 ) { |
83 preserve_br = true; |
139 preserve_br = true; |
84 content = content.replace(/\[caption[\s\S]+?\[\/caption\]/g, function(a) { |
140 content = content.replace( /\[caption[\s\S]+?\[\/caption\]/g, function( a ) { |
85 return a.replace(/<br([^>]*)>/g, '<wp-temp-br$1>').replace(/[\r\n\t]+/, ''); |
141 return a.replace( /<br([^>]*)>/g, '<wp-temp-br$1>' ).replace( /[\r\n\t]+/, '' ); |
86 }); |
142 }); |
87 } |
143 } |
88 |
144 |
89 // Pretty it up for the source editor |
145 // Pretty it up for the source editor |
90 blocklist1 = 'blockquote|ul|ol|li|table|thead|tbody|tfoot|tr|th|td|div|h[1-6]|p|fieldset'; |
146 blocklist1 = 'blockquote|ul|ol|li|table|thead|tbody|tfoot|tr|th|td|div|h[1-6]|p|fieldset'; |
91 content = content.replace(new RegExp('\\s*</('+blocklist1+')>\\s*', 'g'), '</$1>\n'); |
147 content = content.replace( new RegExp( '\\s*</(' + blocklist1 + ')>\\s*', 'g' ), '</$1>\n' ); |
92 content = content.replace(new RegExp('\\s*<((?:'+blocklist1+')(?: [^>]*)?)>', 'g'), '\n<$1>'); |
148 content = content.replace( new RegExp( '\\s*<((?:' + blocklist1 + ')(?: [^>]*)?)>', 'g' ), '\n<$1>' ); |
93 |
149 |
94 // Mark </p> if it has any attributes. |
150 // Mark </p> if it has any attributes. |
95 content = content.replace(/(<p [^>]+>.*?)<\/p>/g, '$1</p#>'); |
151 content = content.replace( /(<p [^>]+>.*?)<\/p>/g, '$1</p#>' ); |
96 |
152 |
97 // Separate <div> containing <p> |
153 // Separate <div> containing <p> |
98 content = content.replace(/<div( [^>]*)?>\s*<p>/gi, '<div$1>\n\n'); |
154 content = content.replace( /<div( [^>]*)?>\s*<p>/gi, '<div$1>\n\n' ); |
99 |
155 |
100 // Remove <p> and <br /> |
156 // Remove <p> and <br /> |
101 content = content.replace(/\s*<p>/gi, ''); |
157 content = content.replace( /\s*<p>/gi, '' ); |
102 content = content.replace(/\s*<\/p>\s*/gi, '\n\n'); |
158 content = content.replace( /\s*<\/p>\s*/gi, '\n\n' ); |
103 content = content.replace(/\n[\s\u00a0]+\n/g, '\n\n'); |
159 content = content.replace( /\n[\s\u00a0]+\n/g, '\n\n' ); |
104 content = content.replace(/\s*<br ?\/?>\s*/gi, '\n'); |
160 content = content.replace( /\s*<br ?\/?>\s*/gi, '\n' ); |
105 |
161 |
106 // Fix some block element newline issues |
162 // Fix some block element newline issues |
107 content = content.replace(/\s*<div/g, '\n<div'); |
163 content = content.replace( /\s*<div/g, '\n<div' ); |
108 content = content.replace(/<\/div>\s*/g, '</div>\n'); |
164 content = content.replace( /<\/div>\s*/g, '</div>\n' ); |
109 content = content.replace(/\s*\[caption([^\[]+)\[\/caption\]\s*/gi, '\n\n[caption$1[/caption]\n\n'); |
165 content = content.replace( /\s*\[caption([^\[]+)\[\/caption\]\s*/gi, '\n\n[caption$1[/caption]\n\n' ); |
110 content = content.replace(/caption\]\n\n+\[caption/g, 'caption]\n\n[caption'); |
166 content = content.replace( /caption\]\n\n+\[caption/g, 'caption]\n\n[caption' ); |
111 |
167 |
112 blocklist2 = 'blockquote|ul|ol|li|table|thead|tbody|tfoot|tr|th|td|h[1-6]|pre|fieldset'; |
168 blocklist2 = 'blockquote|ul|ol|li|table|thead|tbody|tfoot|tr|th|td|h[1-6]|pre|fieldset'; |
113 content = content.replace(new RegExp('\\s*<((?:'+blocklist2+')(?: [^>]*)?)\\s*>', 'g'), '\n<$1>'); |
169 content = content.replace( new RegExp('\\s*<((?:' + blocklist2 + ')(?: [^>]*)?)\\s*>', 'g' ), '\n<$1>' ); |
114 content = content.replace(new RegExp('\\s*</('+blocklist2+')>\\s*', 'g'), '</$1>\n'); |
170 content = content.replace( new RegExp('\\s*</(' + blocklist2 + ')>\\s*', 'g' ), '</$1>\n' ); |
115 content = content.replace(/<li([^>]*)>/g, '\t<li$1>'); |
171 content = content.replace( /<li([^>]*)>/g, '\t<li$1>' ); |
116 |
172 |
117 if ( content.indexOf('<hr') != -1 ) { |
173 if ( content.indexOf( '<option' ) !== -1 ) { |
118 content = content.replace(/\s*<hr( [^>]*)?>\s*/g, '\n\n<hr$1>\n\n'); |
174 content = content.replace( /\s*<option/g, '\n<option' ); |
119 } |
175 content = content.replace( /\s*<\/select>/g, '\n</select>' ); |
120 |
176 } |
121 if ( content.indexOf('<object') != -1 ) { |
177 |
122 content = content.replace(/<object[\s\S]+?<\/object>/g, function(a){ |
178 if ( content.indexOf( '<hr' ) !== -1 ) { |
123 return a.replace(/[\r\n]+/g, ''); |
179 content = content.replace( /\s*<hr( [^>]*)?>\s*/g, '\n\n<hr$1>\n\n' ); |
|
180 } |
|
181 |
|
182 if ( content.indexOf( '<object' ) !== -1 ) { |
|
183 content = content.replace( /<object[\s\S]+?<\/object>/g, function( a ) { |
|
184 return a.replace( /[\r\n]+/g, '' ); |
124 }); |
185 }); |
125 } |
186 } |
126 |
187 |
127 // Unmark special paragraph closing tags |
188 // Unmark special paragraph closing tags |
128 content = content.replace(/<\/p#>/g, '</p>\n'); |
189 content = content.replace( /<\/p#>/g, '</p>\n' ); |
129 content = content.replace(/\s*(<p [^>]+>[\s\S]*?<\/p>)/g, '\n$1'); |
190 content = content.replace( /\s*(<p [^>]+>[\s\S]*?<\/p>)/g, '\n$1' ); |
130 |
191 |
131 // Trim whitespace |
192 // Trim whitespace |
132 content = content.replace(/^\s+/, ''); |
193 content = content.replace( /^\s+/, '' ); |
133 content = content.replace(/[\s\u00a0]+$/, ''); |
194 content = content.replace( /[\s\u00a0]+$/, '' ); |
134 |
195 |
135 // put back the line breaks in pre|script |
196 // put back the line breaks in pre|script |
136 if ( preserve_linebreaks ) |
197 if ( preserve_linebreaks ) { |
137 content = content.replace(/<wp-temp-lb>/g, '\n'); |
198 content = content.replace( /<wp-line-break>/g, '\n' ); |
|
199 } |
138 |
200 |
139 // and the <br> tags in captions |
201 // and the <br> tags in captions |
140 if ( preserve_br ) |
202 if ( preserve_br ) { |
141 content = content.replace(/<wp-temp-br([^>]*)>/g, '<br$1>'); |
203 content = content.replace( /<wp-temp-br([^>]*)>/g, '<br$1>' ); |
|
204 } |
142 |
205 |
143 return content; |
206 return content; |
144 }, |
207 }, |
145 |
208 |
146 _wp_Autop : function(pee) { |
209 _wp_Autop: function(pee) { |
147 var preserve_linebreaks = false, preserve_br = false, |
210 var preserve_linebreaks = false, |
148 blocklist = 'table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|option|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|noscript|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary'; |
211 preserve_br = false, |
149 |
212 blocklist = 'table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre' + |
150 if ( pee.indexOf('<object') != -1 ) { |
213 '|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|legend|section' + |
151 pee = pee.replace(/<object[\s\S]+?<\/object>/g, function(a){ |
214 '|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary'; |
152 return a.replace(/[\r\n]+/g, ''); |
215 |
153 }); |
216 if ( pee.indexOf( '<object' ) !== -1 ) { |
154 } |
217 pee = pee.replace( /<object[\s\S]+?<\/object>/g, function( a ) { |
155 |
218 return a.replace( /[\r\n]+/g, '' ); |
156 pee = pee.replace(/<[^<>]+>/g, function(a){ |
219 }); |
157 return a.replace(/[\r\n]+/g, ' '); |
220 } |
|
221 |
|
222 pee = pee.replace( /<[^<>]+>/g, function( a ){ |
|
223 return a.replace( /[\r\n]+/g, ' ' ); |
158 }); |
224 }); |
159 |
225 |
160 // Protect pre|script tags |
226 // Protect pre|script tags |
161 if ( pee.indexOf('<pre') != -1 || pee.indexOf('<script') != -1 ) { |
227 if ( pee.indexOf( '<pre' ) !== -1 || pee.indexOf( '<script' ) !== -1 ) { |
162 preserve_linebreaks = true; |
228 preserve_linebreaks = true; |
163 pee = pee.replace(/<(pre|script)[^>]*>[\s\S]+?<\/\1>/g, function(a) { |
229 pee = pee.replace( /<(pre|script)[^>]*>[\s\S]+?<\/\1>/g, function( a ) { |
164 return a.replace(/(\r\n|\n)/g, '<wp-temp-lb>'); |
230 return a.replace( /(\r\n|\n)/g, '<wp-line-break>' ); |
165 }); |
231 }); |
166 } |
232 } |
167 |
233 |
168 // keep <br> tags inside captions and convert line breaks |
234 // keep <br> tags inside captions and convert line breaks |
169 if ( pee.indexOf('[caption') != -1 ) { |
235 if ( pee.indexOf( '[caption' ) !== -1 ) { |
170 preserve_br = true; |
236 preserve_br = true; |
171 pee = pee.replace(/\[caption[\s\S]+?\[\/caption\]/g, function(a) { |
237 pee = pee.replace( /\[caption[\s\S]+?\[\/caption\]/g, function( a ) { |
172 // keep existing <br> |
238 // keep existing <br> |
173 a = a.replace(/<br([^>]*)>/g, '<wp-temp-br$1>'); |
239 a = a.replace( /<br([^>]*)>/g, '<wp-temp-br$1>' ); |
174 // no line breaks inside HTML tags |
240 // no line breaks inside HTML tags |
175 a = a.replace(/<[a-zA-Z0-9]+( [^<>]+)?>/g, function(b){ |
241 a = a.replace( /<[a-zA-Z0-9]+( [^<>]+)?>/g, function( b ) { |
176 return b.replace(/[\r\n\t]+/, ' '); |
242 return b.replace( /[\r\n\t]+/, ' ' ); |
177 }); |
243 }); |
178 // convert remaining line breaks to <br> |
244 // convert remaining line breaks to <br> |
179 return a.replace(/\s*\n\s*/g, '<wp-temp-br />'); |
245 return a.replace( /\s*\n\s*/g, '<wp-temp-br />' ); |
180 }); |
246 }); |
181 } |
247 } |
182 |
248 |
183 pee = pee + '\n\n'; |
249 pee = pee + '\n\n'; |
184 pee = pee.replace(/<br \/>\s*<br \/>/gi, '\n\n'); |
250 pee = pee.replace( /<br \/>\s*<br \/>/gi, '\n\n' ); |
185 pee = pee.replace(new RegExp('(<(?:'+blocklist+')(?: [^>]*)?>)', 'gi'), '\n$1'); |
251 pee = pee.replace( new RegExp( '(<(?:' + blocklist + ')(?: [^>]*)?>)', 'gi' ), '\n$1' ); |
186 pee = pee.replace(new RegExp('(</(?:'+blocklist+')>)', 'gi'), '$1\n\n'); |
252 pee = pee.replace( new RegExp( '(</(?:' + blocklist + ')>)', 'gi' ), '$1\n\n' ); |
187 pee = pee.replace(/<hr( [^>]*)?>/gi, '<hr$1>\n\n'); // hr is self closing block element |
253 pee = pee.replace( /<hr( [^>]*)?>/gi, '<hr$1>\n\n' ); // hr is self closing block element |
188 pee = pee.replace(/\r\n|\r/g, '\n'); |
254 pee = pee.replace( /\s*<option/gi, '<option' ); // No <p> or <br> around <option> |
189 pee = pee.replace(/\n\s*\n+/g, '\n\n'); |
255 pee = pee.replace( /<\/option>\s*/gi, '</option>' ); |
190 pee = pee.replace(/([\s\S]+?)\n\n/g, '<p>$1</p>\n'); |
256 pee = pee.replace( /\r\n|\r/g, '\n' ); |
191 pee = pee.replace(/<p>\s*?<\/p>/gi, ''); |
257 pee = pee.replace( /\n\s*\n+/g, '\n\n' ); |
192 pee = pee.replace(new RegExp('<p>\\s*(</?(?:'+blocklist+')(?: [^>]*)?>)\\s*</p>', 'gi'), "$1"); |
258 pee = pee.replace( /([\s\S]+?)\n\n/g, '<p>$1</p>\n' ); |
193 pee = pee.replace(/<p>(<li.+?)<\/p>/gi, '$1'); |
259 pee = pee.replace( /<p>\s*?<\/p>/gi, ''); |
194 pee = pee.replace(/<p>\s*<blockquote([^>]*)>/gi, '<blockquote$1><p>'); |
260 pee = pee.replace( new RegExp( '<p>\\s*(</?(?:' + blocklist + ')(?: [^>]*)?>)\\s*</p>', 'gi' ), '$1' ); |
195 pee = pee.replace(/<\/blockquote>\s*<\/p>/gi, '</p></blockquote>'); |
261 pee = pee.replace( /<p>(<li.+?)<\/p>/gi, '$1'); |
196 pee = pee.replace(new RegExp('<p>\\s*(</?(?:'+blocklist+')(?: [^>]*)?>)', 'gi'), "$1"); |
262 pee = pee.replace( /<p>\s*<blockquote([^>]*)>/gi, '<blockquote$1><p>'); |
197 pee = pee.replace(new RegExp('(</?(?:'+blocklist+')(?: [^>]*)?>)\\s*</p>', 'gi'), "$1"); |
263 pee = pee.replace( /<\/blockquote>\s*<\/p>/gi, '</p></blockquote>'); |
198 pee = pee.replace(/\s*\n/gi, '<br />\n'); |
264 pee = pee.replace( new RegExp( '<p>\\s*(</?(?:' + blocklist + ')(?: [^>]*)?>)', 'gi' ), '$1' ); |
199 pee = pee.replace(new RegExp('(</?(?:'+blocklist+')[^>]*>)\\s*<br />', 'gi'), "$1"); |
265 pee = pee.replace( new RegExp( '(</?(?:' + blocklist + ')(?: [^>]*)?>)\\s*</p>', 'gi' ), '$1' ); |
200 pee = pee.replace(/<br \/>(\s*<\/?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)>)/gi, '$1'); |
266 pee = pee.replace( /\s*\n/gi, '<br />\n'); |
201 pee = pee.replace(/(?:<p>|<br ?\/?>)*\s*\[caption([^\[]+)\[\/caption\]\s*(?:<\/p>|<br ?\/?>)*/gi, '[caption$1[/caption]'); |
267 pee = pee.replace( new RegExp( '(</?(?:' + blocklist + ')[^>]*>)\\s*<br />', 'gi' ), '$1' ); |
202 |
268 pee = pee.replace( /<br \/>(\s*<\/?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)>)/gi, '$1' ); |
203 pee = pee.replace(/(<(?:div|th|td|form|fieldset|dd)[^>]*>)(.*?)<\/p>/g, function(a, b, c) { |
269 pee = pee.replace( /(?:<p>|<br ?\/?>)*\s*\[caption([^\[]+)\[\/caption\]\s*(?:<\/p>|<br ?\/?>)*/gi, '[caption$1[/caption]' ); |
204 if ( c.match(/<p( [^>]*)?>/) ) |
270 |
|
271 pee = pee.replace( /(<(?:div|th|td|form|fieldset|dd)[^>]*>)(.*?)<\/p>/g, function( a, b, c ) { |
|
272 if ( c.match( /<p( [^>]*)?>/ ) ) { |
205 return a; |
273 return a; |
|
274 } |
206 |
275 |
207 return b + '<p>' + c + '</p>'; |
276 return b + '<p>' + c + '</p>'; |
208 }); |
277 }); |
209 |
278 |
210 // put back the line breaks in pre|script |
279 // put back the line breaks in pre|script |
211 if ( preserve_linebreaks ) |
280 if ( preserve_linebreaks ) { |
212 pee = pee.replace(/<wp-temp-lb>/g, '\n'); |
281 pee = pee.replace( /<wp-line-break>/g, '\n' ); |
213 |
282 } |
214 if ( preserve_br ) |
283 |
215 pee = pee.replace(/<wp-temp-br([^>]*)>/g, '<br$1>'); |
284 if ( preserve_br ) { |
|
285 pee = pee.replace( /<wp-temp-br([^>]*)>/g, '<br$1>' ); |
|
286 } |
216 |
287 |
217 return pee; |
288 return pee; |
218 }, |
289 }, |
219 |
290 |
220 pre_wpautop : function(content) { |
291 pre_wpautop: function( content ) { |
221 var t = this, o = { o: t, data: content, unfiltered: content }, |
292 var t = this, o = { o: t, data: content, unfiltered: content }, |
222 q = typeof(jQuery) != 'undefined'; |
293 q = typeof( jQuery ) !== 'undefined'; |
223 |
294 |
224 if ( q ) |
295 if ( q ) { |
225 jQuery('body').trigger('beforePreWpautop', [o]); |
296 jQuery( 'body' ).trigger( 'beforePreWpautop', [ o ] ); |
226 o.data = t._wp_Nop(o.data); |
297 } |
227 if ( q ) |
298 |
228 jQuery('body').trigger('afterPreWpautop', [o]); |
299 o.data = t._wp_Nop( o.data ); |
|
300 |
|
301 if ( q ) { |
|
302 jQuery('body').trigger('afterPreWpautop', [ o ] ); |
|
303 } |
229 |
304 |
230 return o.data; |
305 return o.data; |
231 }, |
306 }, |
232 |
307 |
233 wpautop : function(pee) { |
308 wpautop: function( pee ) { |
234 var t = this, o = { o: t, data: pee, unfiltered: pee }, |
309 var t = this, o = { o: t, data: pee, unfiltered: pee }, |
235 q = typeof(jQuery) != 'undefined'; |
310 q = typeof( jQuery ) !== 'undefined'; |
236 |
311 |
237 if ( q ) |
312 if ( q ) { |
238 jQuery('body').trigger('beforeWpautop', [o]); |
313 jQuery( 'body' ).trigger('beforeWpautop', [ o ] ); |
239 o.data = t._wp_Autop(o.data); |
314 } |
240 if ( q ) |
315 |
241 jQuery('body').trigger('afterWpautop', [o]); |
316 o.data = t._wp_Autop( o.data ); |
|
317 |
|
318 if ( q ) { |
|
319 jQuery( 'body' ).trigger('afterWpautop', [ o ] ); |
|
320 } |
242 |
321 |
243 return o.data; |
322 return o.data; |
244 } |
323 } |
245 } |
324 }; |