Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
FYI -- might want to doc this.
added ckeditor.config.js to the root of my subtheme with the following
<?php
/*
Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/
/*
WARNING: clear browser's cache after you modify this file.
If you don't do this, you may notice that browser is ignoring all your changes.
*/
CKEDITOR.editorConfig = function(config) {
config.indentClasses = [ 'rteindent1', 'rteindent2', 'rteindent3', 'rteindent4' ];
// [ Left, Center, Right, Justified ]
config.justifyClasses = [ 'rteleft', 'rtecenter', 'rteright', 'rtejustify' ];
// The minimum editor width, in pixels, when resizing it with the resize handle.
config.resize_minWidth = 450;
// Protect PHP code tags (<?...?>) so CKEditor will not break them when
// switching from Source to WYSIWYG.
// Uncommenting this line doesn't mean the user will not be able to type PHP
// code in the source. This kind of prevention must be done in the server
// side
// (as does Drupal), so just leave this line as is.
config.protectedSource.push(/<\?[\s\S]*?\?>/g); // PHP Code
config.protectedSource.push(/<code>[\s\S]*?<\/code>/gi); // Code tags
config.extraPlugins = '';
// ALLOW <i></i>
config.protectedSource.push( /<i[\s\S]*?\>/g ); //allows beginning <i> tag
config.protectedSource.push( /<\/i[\s\S]*?\>/g ); //allows ending </i> tag
/*
* Append here extra CSS rules that should be applied into the editing area.
* Example:
* config.extraCss = 'body {color:#FF0000;}';
*/
config.extraCss = '';
/**
* Sample extraCss code for the "marinelli" theme.
*/
if (Drupal.settings.ckeditor.theme == "marinelli") {
config.extraCss += "body{background:#FFF;text-align:left;font-size:0.8em;}";
config.extraCss += "#primary ol, #primary ul{margin:10px 0 10px 25px;}";
}
if (Drupal.settings.ckeditor.theme == "newsflash") {
config.extraCss = "body{min-width:400px}";
}
/**
* CKEditor's editing area body ID & class.
* See http://drupal.ckeditor.com/tricks
* This setting can be used if CKEditor does not work well with your theme by default.
*/
config.bodyClass = '';
config.bodyId = '';
/**
* Sample bodyClass and BodyId for the "marinelli" theme.
*/
if (Drupal.settings.ckeditor.theme == "marinelli") {
config.bodyClass = 'singlepage';
config.bodyId = 'primary';
}
}
/*
* Sample toolbars
*/
//Toolbar definition for basic buttons
Drupal.settings.cke_toolbar_DrupalBasic = [ [ 'Format', 'Bold', 'Italic', '-', 'NumberedList','BulletedList', '-', 'Link', 'Unlink', 'Image' ] ];
//Toolbar definition for Advanced buttons
Drupal.settings.cke_toolbar_DrupalAdvanced = [
['Source'],
['Cut','Copy','Paste','PasteText','PasteFromWord','-','SpellChecker', 'Scayt'],
['Undo','Redo','Find','Replace','-','SelectAll','RemoveFormat'],
['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar'],
['Maximize', 'ShowBlocks'],
'/',
['Format'],
['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiRtl','BidiLtr'],
['Link','Unlink','Anchor','Linkit','LinkToNode','LinkToMenu'],
['DrupalBreak', 'DrupalPageBreak']
];
// Toolbar definiton for all buttons
Drupal.settings.cke_toolbar_DrupalFull = [
['Source'],
['Cut','Copy','Paste','PasteText','PasteFromWord','-','SpellChecker', 'Scayt'],
['Undo','Redo','Find','Replace','-','SelectAll','RemoveFormat'],
['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','Iframe'],
'/',
['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'],
['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiRtl','BidiLtr'],
['Link','Unlink','Anchor','Linkit','LinkToNode', 'LinkToMenu'],
'/',
['Format','Font','FontSize'],
['TextColor','BGColor'],
['Maximize', 'ShowBlocks'],
['DrupalBreak', 'DrupalPageBreak']
];
?>
The important stuff is:
<?php
// ALLOW <i></i>
config.protectedSource.push( /<i[\s\S]*?\>/g ); //allows beginning <i> tag
config.protectedSource.push( /<\/i[\s\S]*?\>/g ); //allows ending </i> tag
?>
Comments
Comment #1
bensnyder CreditAttribution: bensnyder commentedOh -- and be sure to tick "Load ckeditor.config.js from the theme path" as "Yes" under "Advanced Options" if using http://drupal.org/project/ckeditor module
Comment #2
ishmael-sanchez CreditAttribution: ishmael-sanchez commented@bensnyder are you sure this is just an issue with this Foundation theme or is this just a CKEditor/Font-awesome issue. If this is related to Foundation theme please post more details in regards to how this is not working as expected.
Comment #3
bensnyder CreditAttribution: bensnyder commentedIt isn't a "bug" nor is it specific to foundation or this theme. Yes, it is more a CKEditor/Font-Awesome issue. I simply posted it here because I'm currently working with this framework and thought others might find it helpful.
Comment #4
ishmael-sanchez CreditAttribution: ishmael-sanchez commented@bensnyder thanks for your note and the fix, since you state it's not a bug and you posted a fix I'm marking as fixed. I would suggest you post this possibly in the CKEditor/Font-awesome respective issue queues.
Comment #6
kruser CreditAttribution: kruser commentedIt appears that it's also catching the "img" tag with this solution because it starts with "i", so images are getting ckr_protected and commented out from the edit display.
Comment #7
bigimprintwebmaster CreditAttribution: bigimprintwebmaster commentedChanged it a bit to be more specific - it will allow an i tag with a class, so works for font awesome and doesn't interfere with images:
Comment #8
acbramley CreditAttribution: acbramley commentedFor those trying to use the "Custom javascript configuration" textbox in a Ckeditor profile, this solution does not work for some reason. I have other settings in that configuration that work but for some reason the protectedSource had to be added in a custom theme ckeditor.config.js file.
Comment #9
rich.yumul CreditAttribution: rich.yumul commentedThe correct regex is
Courtesy of http://stackoverflow.com/questions/18250404/ckeditor-strips-i-tag
Comment #10
tuthanh CreditAttribution: tuthanh commented#9 helps me to solve the problem with Fontawesome and images not showing on the CKEditor edit mode.
Thanks rich.yumul.
Comment #11
Mario Baron CreditAttribution: Mario Baron commented#9 works on first save but if you return to edit the same block of text containing tag the tags are stripped and need to be entered again.
Comment #12
susannab CreditAttribution: susannab commentedTo allow empty tag like "i", I have added at the end of ckeditor/config.js this line:
CKEDITOR.dtd.$removeEmpty.i = 0;
Comment #13
Alauddin CreditAttribution: Alauddin commented#12 Works!
Thank you.
uncommented the old and added the one liner from #12, now Font Icons work, as well as images display during edit.
Comment #14
knalstaaf CreditAttribution: knalstaaf commentedSince this is a general CKeditor issue it may be more appropriate to move it to the CKeditor issues, so people can look this up there.
Comment #15
jcisio CreditAttribution: jcisio commentedThanks, knalstaaf. I link from your issue, too.
Comment #16
knalstaaf CreditAttribution: knalstaaf commentedI didn't want to put much effort in this so I'm just using an empty space between the tags as follows:
<i class="fa fa-search"> </i>
This works fine, but the disadvantage is that, when you add a border to its container, the container won't look square or circular, but a little stretched and possibly out of center because of that very space.
It's easily solved though: you can adjust the
padding
to the point when everything looks balanced, or you can add a negativeletter-spacing
(try-3px
).Both CSS-approaches work.
Comment #17
jelo CreditAttribution: jelo commentedI tried all kinds of approaches now, e.g. editing the default config.js file or adding a ckeditor.config.js to my theme. Neither worked for me.
Is it correct to adjust the file like this:
For some reason this doesn't seem to fix the issue. As soon as I switch into rich text editor, the icon tags are stripped out.
Comment #18
MrPaulDriver CreditAttribution: MrPaulDriver commented#16 is a practical workaround.
I can't help thinking that ckeditor ought to be playing better with Font Awesome's default markup
Comment #19
Kristina Katalinic CreditAttribution: Kristina Katalinic commented#17 that wont work with latest version of CKEditor library
#18 there are both commercial and free plugins for font awesome but CKEditor module doesn't offer an option to enable either one of them. Since you can hardly find any modern website that doesn't use font awesome option to enable integration with either one of the font awesome plugins should be a priority feature request IMHO
Comment #20
MrPaulDriver CreditAttribution: MrPaulDriver commentedFeature request posted as this issue is marked closed.
https://www.drupal.org/node/2385795
Comment #21
wavesailor CreditAttribution: wavesailor commentedThis is the only option that worked for me: https://www.drupal.org/node/2385795#comment-9681661
Comment #22
haleagar CreditAttribution: haleagar commentedI agree with the solution at https://www.drupal.org/node/2385795#comment-9681661
but the value for
config.extraAllowedContent
is not relevant to this issue.Though I also suggest one more line to render the icons in the CKeditor
config.contentsCss = '//cdn.jsdelivr.net/fontawesome/4.5.0/css/font-awesome.min.css';
Or use a local path if you installed the fontawesome library e.g. /sites/all/libraries/fontawesome/css/font-awesome.css
Or if you are using bootstrap, or any other custom CSS in the editor already you provide contentsCss as an array
This is my markup that enables font awesome, and glyphicons
Comment #23
bmango CreditAttribution: bmango commentedIn my case, I was having the glyphicon spans removed (
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
). I tried several different approaches without success. Finally as mentioned in #0 I created a new ckeditor.config.js file in the root of my theme with the lines:from #22. This didn't quite work, I also had to add a non breaking space inside the span tag for it finally to not be removed, so the eventual span tag became:
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"> </span>
.Comment #24
Pere Orga@bmango thanks, that worked.
Comment #25
cscoleman CreditAttribution: cscoleman commentedThanks, #23 works using
Comment #26
npcoder CreditAttribution: npcoder as a volunteer commentedI'm using Drupal 8.3.3. You can resolve this issue with following steps:
<i>
and Save the configuration.Comment #27
caw67 CreditAttribution: caw67 commenteddoesnt work
Comment #28
Summit CreditAttribution: Summit as a volunteer commentedHi,
Is not necessary to add in ckeditor.config.js. It can also be placed in advanced settings and then add the .js code.
But in my case all that I added..when I click on [CODE] it is stripped again.
It is saved correct, but not shown correct after that in Wyziwyg.
greetings, Martijn
Comment #29
darkodev CreditAttribution: darkodev commentedI found that this is a two-step dance.
1. stop ck from stripping i tags entirely when toggling source mode
2. allow empty i tag
Solutions that worked for me.
[See update in #34 where the only thing in Advanced Javascript is a pointer to a custom config js file in theme folder.]
1. In my CK Advanced Javascript, I could not get the recommended to work, likely because debugging showed no such array.
config.protectedSource.push( /<i[^>]*><\/i>/g )
I use this instead.
config.protectedSource = [/<i[^>]*><\/i>/g];
2. In my custom theme config file
CKEDITOR.dtd.$removeEmpty['i'] = false;
You can do this with other tags, of course, although this is bad html as much as empty i tags are.
CKEDITOR.dtd.$removeEmpty['span'] = false;
Comment #30
griffinhere CreditAttribution: griffinhere commented@darkodev your solution (#29) worked for me. Thank you *-*
Comment #31
bilel.mebarki CreditAttribution: bilel.mebarki commentedin your template add :
Comment #32
bilel.mebarki CreditAttribution: bilel.mebarki commentedan other solution juste with HTML add a space " "
<span class="glyphicon glyphicon-folder-open"> </span>not <span class="glyphicon glyphicon-folder-open"></span>
Comment #33
erok415 CreditAttribution: erok415 as a volunteer and at Molly Duggan Associates commentedHi @darkdodev,
What did you mean on Comment #29 when you said "In my custom theme config file"? Are you referring to the .info or template.php file?
E.
Comment #34
darkodev CreditAttribution: darkodev commented@erok415
Neither. In CKEditor "Custom JavaScript configuration" I now have a single line pointing to a custom config file in my theme where I do all the work:
config.customConfig='/path/to/theme/js/ckeditor_custom_config.js';
In that file, I do
Comment #35
renguer0 CreditAttribution: renguer0 as a volunteer commentedDoes anybody know how can we add this code in D8 module?
Striping tags from CKEditor is really frustrating.
Comment #36
timfletcher CreditAttribution: timfletcher as a volunteer commented#29 from @darkodev worked for me (I'm on Drupal 8.9.11).
So it's all in once place, after lots of hunting, here's how to apply custom configuration to CKEditor in Drupal 8, without PHP or editing any core files:
1. Install and enable the CKEditor Custom Config module
2. Create an empty file called 'my.custom.ckeditor.config.js' in your theme
3. Edit your text format (/admin/config/content/formats/) and add this line under 'CKEditor Custom Configuration' (from #34):
customConfig = "/path/to/my/theme/my.custom.ckeditor.config.js"
4. Inside
my.custom.ckeditor.config.js
, add:5. Rebuild the site cache
Comment #37
Summit CreditAttribution: Summit as a volunteer commentedThis is awesome, thanks!
gr,