Wiki source code of WYSIWYG Editor Configuration

Version 19.1 by Marius Dumitru Florea on 2011/02/16 15:50

Show last authors
1 = WYSIWYG Editor Configuration =
2
3 (% class="floatinginfobox" %)
4 (((**Contents**
5
6 {{toc/}})))
7
8
9 Welcome to the WYSIWYG editor configuration guide. This page will help you configure XWiki's GWT rich text editor so that it meets your needs.
10
11 {{velocity}}{{html}}#info("The information from this page applies only to the new GWT-based WYSIWYG editor that comes with XWiki 2.0 syntax."){{/html}}{{/velocity}}
12
13 == Quick Reference ==
14
15 === Configuration Parameters ===
16
17 (% style="clear:right" %)
18 |=(% width="15%" %)Parameter Name|=(% width="50%" %)Description|=Default Value
19 |**allowExternalImages**|Specifies if inserting external images is allowed or not. Setting this configuration parameter to ##false## hides the //External// tab from the Insert Image dialog.|##true##
20 |**colors**|The list of colors available on the color picker. Colors are specified by their hex code and are separated by comma.|###000000,#444444,#666666,#999999,#CCCCCC,#EEEEEE,#F3F3F3,#FFFFFF,
21 #FF0000,#FF9900,#FFFF00,#00FF00,#00FFFF,#0000FF,#9900FF,#FF00FF,
22 #F4CCCC,#FCE5CD,#FFF2CC,#D9EAD3,#D0E0E3,#CFE2F3,#D9D2E9,#EAD1DC,
23 #EA9999,#F9CB9C,#FFE599,#B6D7A8,#A2C4C9,#9FC5E8,#B4A7D6,#D5A6BD,
24 #E06666,#F6B26B,#FFD966,#93C47D,#76A5AF,#6FA8DC,#8E7CC3,#C27BA0,
25 #CC0000,#E69138,#F1C232,#6AA84F,#45818E,#3D85C6,#674EA7,#A64D79,
26 #990000,#B45F06,#BF9000,#38761D,#134F5C,#0B5394,#351C75,#741B47,
27 #660000,#783F04,#7F6000,#274E13,#0C343D,#073763,#20124D,#4C1130##
28 |**colorsPerRow**|The maximum number of colors the color picker should display on a row|##8##
29 |**convertInput**|Whether to convert the input (the value taken from the hook element) or not. Set this parameter to ##true## if the value of the plain text area being replaced represents wiki syntax. Leave it unset or set it to ##false## if the WYSIWYG editor input is HTML|##false##
30 |**debug**|Whether to load the editor in debug mode or not. In debug mode you can see the dirty HTML generated by the editor, the cleaned HTML, the source text and the rendering events that were triggered during the conversion of the cleaned HTML to source text. The syntax of the source text is controlled by the **syntax** parameter.|##false##
31 |**defaultEditor**|Specifies the default tab when **displayTabs** is ##true##. Use ##wysiwyg## to load initially the WYSIWYG editor and ##source## to load initially the source editor.|##source##
32 |**displayTabs**|Whether to display the WYSIWYG/Source tabs or not. The source editor is not available when the tabs are not displayed. The default tab is controlled by the **defaultEditor** parameter.|##false##
33 |**fontNames**|A comma-separated list of font names the user can use to format the text. The font name list box from the toolbar is filled with this list. See font-family CSS property for allowed values.|##andale mono, arial, arial black, book antiqua, comic sans ms, courier new, georgia, helvetica, impact, symbol, tahoma, terminal, times new roman, trebuchet ms, verdana, webdings, wingdings##
34 |**fontSizes**|A comma-separated list of font sizes the user can use to format the text. The font size list box from the toolbar is filled with this list. See font-size CSS property for allowed values. Note that relative sizes (like ##smaller##) are not well detected by the editor.|##8pt, 10pt, 12pt, 14pt, 18pt, 24pt, 36pt##
35 |**hookId**|The id of the HTML element replaced by the editor. Usually the hook element is a plain text area.|//None//
36 |**inputURL**|The URL of the edited document. Make sure the URL obeys the same origin policy.|##about:blank##
37 |**insertimages**|Set to ##currentpage## to restrict the image upload and image selection to the edited page. This parameter is used by the insert image feature.|//None//
38 |**linkfiles**|Set to ##currentpage## to restrict the attachment upload and attachment selection to the edited page. This parameter is used by the create link to attachment feature.|//None//
39 |**menu**|A space-separated list of editor plugins that should place their menu entries on the top menu bar. The top menu bar is not displayed if this list is empty, which is the case by default. Make sure the plugins you put on the menu bar are loaded by the editor; see the **plugins** parameter.|//Empty string//
40 |**page**|The name of the edited page. This parameter is used by many plugins in order to be aware of the editing context. See also the **space** and **wiki** parameters.|//None//
41 |**plugins**|A space-separated list of editor plugins that will be loaded. Only the plugins that can work off-line, without the need of a service, are loaded by default. If a plugin provides [[editing features>>#HPluginsandFeatures]] then you have to change the **toolbar** parameter in order to enabled them.|##submit line separator text valign justify list indent history format font color symbol table##
42 |**rootUI**|A space-separated list of plugins that extend the editor UI. Make sure the specified plugins are loaded; see the **plugins** parameter.|##submit##
43 |**space**|The space where the edited page resides. This parameter is used by many plugins in order to be aware of the editing context. See also the **page** and **wiki** parameter.|//None//
44 |**styleNames**|The list of predefined styles, in JSON format. E.g. ##[{...}, {"name": "todo", "label": "TODO", "inline": false}, {...}]##. A style name is a CSS class name. Only the "name" property is required for each style. "label" equals "name" by default. "inline" is ##true## by default.|##[]##
45 |**syncPage**|The full name of the page edited in real-time.|//None//
46 |**syncReset**|Set to ##1## to reset the synchronization during a real-time editing.|##0##
47 |**syntax**|The syntax of the edited document. Make sure the specified syntax is supported by the rendering module. Precisely, there has to be a parser and a renderer for the specified syntax.|##xhtml/1.0##
48 |**toolbar**|A space-separated list of features to be placed on the toolbar. Each feature is provided by a plugin so make sure the required plugins are loaded; see the **plugins** parameter. You can group features by using the pipe **~|** symbol. To force a multiple line toolbar use the slash **/** symbol.|##bold italic underline strikethrough teletype ~| subscript superscript ~| justifyleft justifycenter justifyright justifyfull ~| unorderedlist orderedlist ~| outdent indent ~| undo redo ~| format ~| fontname fontsize forecolor backcolor ~| hr removeformat symbol##
49 |**wiki**|The wiki where the edited page resides. This parameter is used by many plugins in order to be aware of the editing context. See also the **page** and **space** parameter.|//None//
50
51 === XWiki Preferences ===
52
53 Each preference listed below has a matching configuration parameter which it overwrites.
54
55 |=Preference Name|=Type|=Configuration Parameter
56 |**wysiwyg.plugins**|TextArea|plugins
57 |**wysiwyg.menu**|String|menu
58 |**wysiwyg.toolbar**|TextArea|toolbar
59
60 === Plugins and Features ===
61
62 The //Plugin Name//, //Toolbar Features// and //Menu// columns match the **plugins**, **toolbar** and **menu** configuration parameters respectively.
63
64 |=Plugin Name|=Description|=Toolbar Features|=Menu
65 |**color**|Controls the colors used inside the rich text area|(((* **forecolor**: text color
66 * **backcolor**: highlight color)))|-
67 |**font**|Controls the font used.|(((* **fontname**: change the font name
68 * **fontsize**: change the font size)))|-
69 |**format**|Applies or removes predefined text styles.|(((* **format**: format the text as heading or paragraph
70 * **removeformat**: remove all in-line text formatting)))|-
71 |**history**|Controls the editing history.|(((* **undo**: go one step back in the editing history
72 * **redo**: go one step forward in the editing history)))|-
73 |**image**|Adds support for inserting and editing images|-|**image**
74 |**import**|Adds support for importing external content|(((* **import:officefile**: import office document
75 * **paste**: paste rich text from the clipboard)))|**import**
76 |**indent**|Allows you to increase or decrease the indentation of list items.|(((* **outdent**: decrease indentation
77 * **indent**: increase indentation)))|-
78 |**justify**|Controls the text alignment.|(((* **justifyleft**: align text left
79 * **justifycenter**: center text
80 * **justifyright**: align text right
81 * **justifyfull**: justify text)))|-
82 |**line**|Controls the behavior of the Enter key inside the rich text area.|-|-
83 |**link**|Add support for creating and editing different kind of links|-|**link**
84 |**list**|Adds support for creating lists|(((* **unorderedlist**: creates bulleted lists
85 * **orderedlist**: numbered lists)))|-
86 |**macro**|Adds support for inserting and editing macros|(((* **macro:macroId**: insert the macro with the specified identifier, e.g. use macro:velocity to add a button on the tool bar that triggers the insert Velocity macro wizard)))|**macro**
87 |**separator**|Offers different kind of content and toolbar separators|(((* **hr**: inserts a horizontal ruler
88 * **|**: separates toolbar features in groups
89 * **/**: breaks the toolbar in multiple lines)))|-
90 |**style**|Enhances the editor with the ability to apply predefined styles to the current text selection.|(((* **stylename**: installs a list box on the tool bar with the available styles)))|-
91 |**submit**|Ensures that the content of the editor is submitted and also cached by the browser.|-|-
92 |**symbol**|Allows you to insert a special symbol.|**symbol**|-
93 |**table**|Adds support for inserting and editing tables.|-|**table**
94 |**text**|Offers standard text formatting.|(((* **bold**: formats text as bold
95 * **italic**: formats text as italic
96 * **underline**: formats text as underlined
97 * **strikethrough**: formats text as stroke through
98 * **teletype**: formats text as monospace)))|-
99 |**valign**|Allows you to write simple formulas.|(((* **subscript**: formats the text as subscript
100 * **superscript**: formats the text as superscript)))|-
101
102 == Configuration ==
103
104 === By editing XWiki preferences ===
105
106 {{velocity}}{{html}}#warning("Configuring the WYSIWYG editor through XWiki Preferences is possible only since XWiki Enterprise 2.0."){{/html}}{{/velocity}}
107
108 Edit **XWiki.XWikiPreferences** page with the object editor and fill the properties specified in the [[XWiki Preferences>>#HXWikiPreferences]] section. If the **XWiki.XWikiPreferences** object doesn't have those properties then you'll have to add them to the class. Finally, reload the edited page to see the WYSIWYG editor changes.
109
110 === By editing the velocity templates ===
111
112 The WYSIWYG editor is configured by a velocity macro named **wysiwyg_storeConfig** which can be found in **templates/macros.vm**. In older versions of XWiki Enterprise (prior to 1.9) the code of the **wysiwyg_storeConfig** macro is placed in **templates/editwysiwygnew.vm**. Use the parameters listed in the [[Configuration Parameters>>#HConfigurationParameters]] section to configure the editor. You may have to restart the server in order for the changes to take effect because velocity templates can be cached at application startup.
113
114 === By customizing the skin ===
115
116 You have to overwrite the **wysiwyg_storeConfig** velocity macro from **templates/macros.vm** in your skin. Reload the edited page to see the WYSIWYG editor changes.
117
118 == Examples ==
119
120 === Enable toolbar features ===
121
122 Editing features (e.g. make text bold, change text color) are provided by editor plugins (e.g. text, color). Another way to see this is that similar editing features are grouped together in a plugin (e.g. changing the background color and the text color features form the color plugin). In order to enable a feature and make it available on the toolbar for instance you first have to enable the plugin that provides that feature.
123
124 Let's see how you can add the Background Color button to the WYSIWYG editor toolbar. In this example we're going to edit **macros.vm** template but you can do the same using only XWiki preferences.
125
126 First, search for the **wysiwyg_storeConfig** velocity macro in **templates/macros.vm**. This macro should have a line like this:
127
128 {{code}}
129 #set($ok = $parameters.put('plugins', $xwiki.getXWikiPreference('wysiwyg.plugins', "submit line separator embed text valign list indent history format symbol link image table macro import#if($full && $request.sync) sync#end")))
130 {{/code}}
131
132 Add the **color** plugin:
133
134 {{code}}
135 #set($ok = $parameters.put('plugins', $xwiki.getXWikiPreference('wysiwyg.plugins', "submit line separator embed text color valign list indent history format symbol link image table macro import#if($full && $request.sync) sync#end")))
136 {{/code}}
137
138 The position of the plugin name in the list is not important. What matters is that it appears in the list so the WYSIWYG editor can load it. You can find what plugins are available in [[Plugins and Features>>#HPluginsandFeatures]] section of this page.
139
140 Next you have to add **backcolor** feature to the toolbar. Change the following line:
141
142 {{code}}
143 #set($ok = $parameters.put('toolbar', $xwiki.getXWikiPreference('wysiwyg.toolbar', 'bold italic underline strikethrough | subscript superscript | unorderedlist orderedlist | outdent indent | undo redo | format | hr symbol | paste')))
144 {{/code}}
145
146 to
147
148 {{code}}
149 #set($ok = $parameters.put('toolbar', $xwiki.getXWikiPreference('wysiwyg.toolbar', 'bold italic underline strikethrough | subscript superscript | unorderedlist orderedlist | outdent indent | undo redo | format | hr symbol | paste | backcolor')))
150 {{/code}}
151
152 You can place the Background Color button anywhere on the toolbar. Just make sure you leave a space before and after, unless its the first or the last feature on the toolbar.
153
154 That's it. You have to restart your server because macros.vm is cached by default at application startup. Reload the edited page and you should see the Background Color button appear on the toolbar of your WYSIWYG editor.
155
156 === Add an 'Insert HTML macro' button on the tool bar ===
157
158 Suppose you use the HTML macro very often and thus you'd like to have a quick way to insert it from the tool bar. You don't use the HTML macro that often? No problem, it works with any macro. You just need to follow this steps:
159
160 1. Add ##macro:html## (or ##macro:yourCoolMacro## if you like ##yourCoolMacro## more) to the tool bar configuration as explained in the previous example.
161 1. Set a custom icon for the tool bar button by adding:
162
163 {{code language=none}}
164 .macro-html {
165 background-image:url("/xwiki/resources/icons/silk/html.gif") !important;
166 }
167 {{/code}}
168
169 to your skin. Of course you can use a different icon and you can replace ##html## with the identifier of your macro. The easiest way to adds this CSS fragment to the skin is by adding a ##XWiki.StyleSheetExtension## object to a page and set it to be always used on the wiki.

Get Connected