This issue is similar to http://drupal.org/node/775076, but has nothing to do with Teaser Breaks.

The issue here is that, after adding the line

config.protectedSource.push( /<tex[\s\S]*?\/tex>/g );

to /libraries/ckeditor/config.js

all content enclosed within the <tex> tags (I'm using the Drutex module) are protected from html encoding during preview, but not after clicking "save". I need to prevent the amersand character, which means something special in LaTex, from being html encoded. This problem is a real mystery to me now, and I'm not sure even where to look for a solution. Any ideas?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ShaunDychko’s picture

Title: CKEditor protectedSource feature works on Preview, but not on Save » CKEditor protectedSource feature breaks when existing node is edited.

To give other problem solvers some more insight: the issue is that CKEditor html encodes the special characters (like ampersand) when the text field is initially loaded after choosing to edit the node. Here's what happens (with config.js modified as above):

Create a piece of content using the "source" view with CKEditor, and type an ampersand, and click save. In the database you can verify that this will be stored as a single character, which is desired (it isn't html encoded).

Then choose to edit this node. Here's where the problems start. When CKEditor loads the text field it WILL html encode the ampersand, despite the modification to config.js. I've also tried adding:

	config.htmlEncodeOutput = false;
	config.entities = false;

to /libraries/ckeditor/config.js but these don't solve the problem. There is a problem with the way the editor loads text fields in that it ignores the config.js entries.

Note: I've abandoned this issue in favour of using http://drupal.org/project/fckeditor which, with

FCKConfig.ProtectedSource.Add( /<tex[\s\S]*?\/tex>/g );

in modules/fckeditor/fckeditor.config.js works great.

ShaunDychko’s picture

Status: Active » Fixed
TwoD’s picture

Category: bug » support

It does not appear to be the entities plugin which does the conversion, removing it has no effect. I'm also unable to stop CKEditor from outputting ampersands as &amp; with or without Wysiwyg module.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

BrightBold’s picture

Title: CKEditor protectedSource feature breaks when existing node is edited. » Preventing CKEditor from converting HTML entities
Status: Closed (fixed) » Active

Hope I'm not hijacking this issue - my concern is different but the root cause is the same.

I am trying to use WYSIWYG, CKEditor, and Typogrify together. But CKEditor's HTML entities conversion turns the quotation marks into &quot;s and apostrophes into &#39;s, breaking Typogrify's ability to transform them into typographer's quotes.

I also made the config.entities = false change to CKEditor's config.js, but it doesn't appear to be reading that file. I assumed this was because of WYSIWYG but TwoD makes it sound like it's a CKEditor problem.

At any rate, I was able to temporarily solve the problem by hacking ckeditor.js to include the line CKEDITOR.config.entities=false; but of course this is not an ideal solution, since I'll lose my modification if I upgrade CKEditor. It looks like my choices for doing this "the Drupal way" are to write a module to handle it using HOOK_wysiwyg_editor_settings_alter (per this discussion), which I may or may not actually be capable of doing, or wait for WYSIWYG 3.0, which will offer ways to configure individual editors.

Have I interpreted what I've read correctly? Are these the options? Any other suggestions?

TwoD’s picture

Component: Editor - CKEditor » Editor - CKeditor
Status: Closed (fixed) » Fixed

Yes, those are currently your options. I'm still not sure where all the entity conversions in CKEditor happen. If you're able to influence quotes using that setting I think the entity plugin is doing at least that part. (Not able to look at the code right now.)
A hook implementation to do what you need would look like this:

/**
* Implementation of hook_wysiwyg_editor_settings_alter().
*/
function MYMODULE_wysiwyg_editor_settings_alter(&$settings, $context) {
  if($context['profile']->editor == 'ckeditor') {
    $settings['entities'] = FALSE;
  }
}

All you should need is that in MYMODULE.module and a MYMODULE.info file and you're ready to go. Info file specs can be found at Writing .info files (Drupal 6.x)

BrightBold’s picture

Status: Active » Fixed

Haven't tried that yet but it looks straightforward enough - I can do that! Thanks.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

borgo’s picture

Edit your profile, under Advanced settings at the bottom set Custom javascript configuration:

config.entities = false;

I needed to stop CK from converting diacritics ščľžď etc to HTML entities. This did it for me.

gstokes’s picture

Component: Editor - CKeditor » Code

This worked for me thanks this has been wrecking my head.

TwoD’s picture

Component: Code » Editor - CKEditor

If that worked, you are using ckedtor.module and not wysiwyg.module.

Wysiwyg module will also have a GUI for setting things like this once #313497: Allow configuration of advanced editor settings is done.

John Pitcairn’s picture

tagging for reference, thanks

BrightBold’s picture

FileSize
889 bytes

For anyone who's having this problem and doesn't feel comfortable creating a module, here's TwoD's code from #7 in module format. (Note - d.o. renamed it on upload, so if you have trouble uncompressing, just remove the underscore in the extension.)

Works beautifully - now my straight quotes get converted to typographer's quotes by Typogrify. Thanks @TwoD!

The WYSIWYG editor configuration GUI will be a good improvement, but this is great for now!

BrightBold’s picture

FileSize
682 bytes

Oops. Just learned the attachment above was empty. Try this one:

TwoD’s picture

If you've got the Teaser Break plugin enabled, it will convert HTML entites back to their character form due to a bug. Please try the new xhtml_callback (D7) branch in git and see #510552: Invalid XHTML: missing trailing slashes, absolute urls and uppercase tags for progress.

ShaunDychko’s picture

Shocking triumph!

By creating a module containing the following three lines (replace MYMODULE with your own module name), CKEditor keeps it's hands off LaTeX code, and the code is even displayed in the WYSIWYG view (this was a problem when using the "ProtectedSource" solution before http://drupal.org/node/732162). The LaTeX code is editable only when "Disable Rich Text" is selected.

/**
* Implementation of hook_wysiwyg_editor_settings_alter().
* Prevents CKEditor from encoding html entities, such as ampersands, for
* compatibility with DRUTEX module.
*/
function MYMODULE_wysiwyg_editor_settings_alter(&$settings, $context) {
  if($context['profile']->editor == 'ckeditor') {
    $settings['entities'] = FALSE;
    $settings['basicEntities'] = FALSE;
    $settings['disableReadonlyStyling'] = TRUE;
  }
}

The following is rendered by Drutex as a proper LaTeX table:

<tex contenteditable="false"> \begin{tabular}{ l c r } 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \\ \end{tabular}</tex>

Tested with:
CKEditor 3.6.1.7072
WYSIWYG 6.x-2.4

This still isn't entirely user friendly for the website editors since they must

  1. Click "Disable Rich Text"
  2. type <tex contenteditable="false"> ...</tex> around their LaTeX code, and not forget the contenteditable="false" attribute.

Can anyone improve on this?

jeff.hartman’s picture

I've loaded this module (per BrightBold in #13) and have also tried via function in an existing custom module, but can't seem to get the function loading.

I guess it's not clear as to where I should see it loading. Do these overrides happen on every load of form fields that use the CKEditor or does this load when you configure your WYSIWYG profiles?

I've testing by simply putting a print_r($context) and print_r($settings) within the function itself and nothing is outputted to the page.

Thoughts?

I'm using CKEditor 3.4.1.5892 on Drupal 6.2x.

UPDATE: Got this working now, but the difference is that I cannot pass $settings and $context by reference to the function. I see watchdog entries if I do.

DuaelFr’s picture

#16 worked for me (but my use case has no relation with tex)

I was looking for a way to disable entities auto conversion because it is not really good with Diff module.

ShaunDychko’s picture

Glad you found #16 useful. Note that the ampersand in front of the $context variable should be removed (it throws an error in PHP 5.3.x). It should be:

/**
* Implementation of hook_wysiwyg_editor_settings_alter().
* Prevents CKEditor from encoding html entities, such as ampersands, for
* compatibility with DRUTEX module.
*/
function MYMODULE_wysiwyg_editor_settings_alter(&$settings, $context) {
  if($context['profile']->editor == 'ckeditor') {
    $settings['entities'] = FALSE;
    $settings['basicEntities'] = FALSE;
    $settings['disableReadonlyStyling'] = TRUE;
  }
}
TwoD’s picture

Component: Editor - CKeditor » Editor - CKEditor
Status: Fixed » Closed (fixed)

Yes, $context is not intended to be passed by reference (modifying it would confuse the heck out of Drupal/Wysiwyg) so it should not use the ampersand. Some of my earliest hook_wysiwyg_editor_settings_alter() examples included it by mistake and have been copy/pasted around quite a lot. But, I try to fix them as I find them so I just removed it from my previous post. Could you please edit #16 as well, Shaun? Just in case someone copy/pastes it without noticing the ampersand. Thanks.

ShaunDychko’s picture

#16 looks correct now. Cheers.

dlats’s picture

Added the module, but getting & as &; on the first save, then & on the next edit. What else could be wrong/misset?

dlats’s picture

Oops. Some more info. This is part of a url in an anchor. The second & in the above post was fully an html entity not just an &.

dlats’s picture

Found it. I used $settings['forceSimpleAmpersand'] = TRUE; instead and disabled the module called "Pathologic".

MatteNoob’s picture

Been working on this for hours on end now. I'm trying to use drutex with wysiwyg and ckeditor.

The ampersand is converted to &amp;. I have written a little module which loads an additional js-file where I try to set the properties.

The .info

name = Drutex CKeditor Compability
description = Prevents CKEditor from encoding html entities, such as ampersands, for compatibility with DRUTEX module.
core = 6.x
package = "Input filters"
dependencies[] = wysiwyg

version = "6.x-1.0"
core = "6.x"

The .module

/**
* Implements hook_wysiwyg_editor_settings_alter().
*/
function drutex_ckeditor_compability_wysiwyg_editor_settings_alter(&$settings, $context) {
  if ($context['profile']->editor == 'ckeditor') {
    $settings['customConfig'] = '/' . drupal_get_path('module', 'drutex_ckeditor_compability') . '/ckeditor.config.js';
    drupal_set_message('Custom WYSIWYG editor settings loaded');
  }
}

I've added the drupal_set_message to see if it is run, and it is.

The .js

CKEDITOR.editorConfig = function(config) {
    config.entities = false;
    config.htmlEncodeOutput = false;
}

However, when I type something in the CKeditor field and click source the entities are converted to &amp;

Also if I write some latex and just save the output drutex parses images with <br>, &amp; and other htmlentities. What am I missing, please?

ShaunDychko’s picture

I've been using #19 with the same set-up as you have (Drutex with CKEditor with WYSIWYG), and it works for me.

runeasgar’s picture

I can't get this working. Every time I "edit" a node with a WYSIWYG body that contains quote characters, they get converted to HTML entities in the WYSIWYG source, and when I save, it then outputs those entities directly to the browser. This has unfortunately completely crippled a site I was working on and I now have to postpone launch :\

I put this module in place to no avail:

<?php
/**
* Implementation of hook_wysiwyg_editor_settings_alter().
*/
function fix_ckeditor_wysiwyg_editor_settings_alter(&$settings, $context) {
  if($context['profile']->editor == 'ckeditor') {
    $settings['basicEntities'] = FALSE;
    $settings['entities'] = FALSE;
  }
}