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