2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
\r
3 * Copyright (C) 2003-2010 Frederico Caldeira Knabben
\r
5 * == BEGIN LICENSE ==
\r
7 * Licensed under the terms of any of the following licenses at your
\r
10 * - GNU General Public License Version 2 or later (the "GPL")
\r
11 * http://www.gnu.org/licenses/gpl.html
\r
13 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
\r
14 * http://www.gnu.org/licenses/lgpl.html
\r
16 * - Mozilla Public License Version 1.1 or later (the "MPL")
\r
17 * http://www.mozilla.org/MPL/MPL-1.1.html
\r
21 * This is a sample implementation for a custom Data Processor for basic BBCode.
\r
27 * Returns a string representing the HTML format of "data". The returned
\r
28 * value will be loaded in the editor.
\r
29 * The HTML must be from <html> to </html>, eventually including
\r
31 * @param {String} data The data to be converted in the
\r
32 * DataProcessor specific format.
\r
34 ConvertToHtml : function( data )
\r
36 // Convert < and > to their HTML entities.
\r
37 data = data.replace( /</g, '<' ) ;
\r
38 data = data.replace( />/g, '>' ) ;
\r
40 // Convert line breaks to <br>.
\r
41 data = data.replace( /(?:\r\n|\n|\r)/g, '<br>' ) ;
\r
44 data = data.replace( /\[url\](.+?)\[\/url]/gi, '<a href="$1">$1</a>' ) ;
\r
45 data = data.replace( /\[url\=([^\]]+)](.+?)\[\/url]/gi, '<a href="$1">$2</a>' ) ;
\r
48 data = data.replace( /\[b\](.+?)\[\/b]/gi, '<b>$1</b>' ) ;
\r
51 data = data.replace( /\[i\](.+?)\[\/i]/gi, '<i>$1</i>' ) ;
\r
54 data = data.replace( /\[u\](.+?)\[\/u]/gi, '<u>$1</u>' ) ;
\r
56 return '<html><head><title></title></head><body>' + data + '</body></html>' ;
\r
60 * Converts a DOM (sub-)tree to a string in the data format.
\r
61 * @param {Object} rootNode The node that contains the DOM tree to be
\r
62 * converted to the data format.
\r
63 * @param {Boolean} excludeRoot Indicates that the root node must not
\r
64 * be included in the conversion, only its children.
\r
65 * @param {Boolean} format Indicates that the data must be formatted
\r
66 * for human reading. Not all Data Processors may provide it.
\r
68 ConvertToDataFormat : function( rootNode, excludeRoot, ignoreIfEmptyParagraph, format )
\r
70 var data = rootNode.innerHTML ;
\r
72 // Convert <br> to line breaks.
\r
73 data = data.replace( /<br(?=[ \/>]).*?>/gi, '\r\n') ;
\r
76 data = data.replace( /<a .*?href=(["'])(.+?)\1.*?>(.+?)<\/a>/gi, '[url=$2]$3[/url]') ;
\r
79 data = data.replace( /<(?:b|strong)>/gi, '[b]') ;
\r
80 data = data.replace( /<\/(?:b|strong)>/gi, '[/b]') ;
\r
83 data = data.replace( /<(?:i|em)>/gi, '[i]') ;
\r
84 data = data.replace( /<\/(?:i|em)>/gi, '[/i]') ;
\r
87 data = data.replace( /<u>/gi, '[u]') ;
\r
88 data = data.replace( /<\/u>/gi, '[/u]') ;
\r
90 // Remove remaining tags.
\r
91 data = data.replace( /<[^>]+>/g, '') ;
\r
97 * Makes any necessary changes to a piece of HTML for insertion in the
\r
98 * editor selection position.
\r
99 * @param {String} html The HTML to be fixed.
\r
101 FixHtml : function( html )
\r
107 // This Data Processor doesn't support <p>, so let's use <br>.
\r
108 FCKConfig.EnterMode = 'br' ;
\r
110 // To avoid pasting invalid markup (which is discarded in any case), let's
\r
111 // force pasting to plain text.
\r
112 FCKConfig.ForcePasteAsPlainText = true ;
\r
114 // Rename the "Source" buttom to "BBCode".
\r
115 FCKToolbarItems.RegisterItem( 'Source', new FCKToolbarButton( 'Source', 'BBCode', null, FCK_TOOLBARITEM_ICONTEXT, true, true, 1 ) ) ;
\r
117 // Let's enforce the toolbar to the limits of this Data Processor. A custom
\r
118 // toolbar set may be defined in the configuration file with more or less entries.
\r
119 FCKConfig.ToolbarSets["Default"] = [
\r
121 ['Bold','Italic','Underline','-','Link'],
\r