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.
Hi folks,
Having a bit of an issue with CKEditor; I want it to completely leave my source code alone. I don't want CKEditor to reformat the HTML and "helpfully" indent it (can you tell I'm typing this through slightly-gritted teeth? ;o) as it never quite gets things right.
So, in the setup screen I've disabled "apply source formatting". Now when I edit the HTML and save, everything is munged into one line, which is less than pretty and a pain in the backside to edit.
How can I get CKEditor to just leave my bloomin' code alone entirely?!
Any and all help greatly appreciated!
Best wishes,
Al
Comment | File | Size | Author |
---|---|---|---|
Screen shot 2011-05-04 at 14.31.39.png | 22.36 KB | alexharries |
Comments
Comment #1
fietserwinHave a look at #594548: Viewing source removes new lines with fckeditor and close this issue if it is a duplicate or remarks in that issue solve your problem.
Comment #2
TwoDI'm afraid that's not possible, due to how CKEditor generates the output. It completely rebuilds the source from scratch based on the DOM tree in the editing area each time the content is requested from it. But, it's possible to control how it formats your markup.
CKEditor has a class called the Data Processor, which uses an HTML Writer class to create the actual markup tag by tag. This HTML Writer has a bunch of settings we can change to tell it where to put indents and linebreaks. Formatting can also be turned off completely minify the output. These settings are currently not controllable via Wysiwyg module and its GUI or the settings alter hook (we need at least #313497: Allow configuration of advanced editor settings for that).
What I did when implementing CKEditor was to make the "Apply source formatting" checkbox toggle between no formatting at all and a set of rules I thought reasonable. The consequence is of course, as you mentioned, that the editor won't get it quite right for everyone, but it beats having no formatting at all.
You can see the rules Wysiwyg sets in ckeditor-3.0.js
There's a reference page in the CKEditor wiki on Output Formatting.
If you can give examples of how you'd like your markup to be formatted, I can come up with the appropriate rules to set. Actually changing them can't be done without hacking the ckeditor-3.0.js implementation at this point. I'm hoping to change that as soon as I can test the work I've been doing on the advanced settings issue.
Comment #3
thekevinday CreditAttribution: thekevinday commentedI am changing this to a feature request because I believe the context of "feature request" fits this better than "support request".
I would like to be able to customize the following "formatting" approaches:
The most important case I want to handle is indentationChars.
My accessibility scanner (quail-lib) produces lots of report failures because of the use of tab characters
'\t'
inside of html markup. I would prefer to use spaces instead. My standard is two spaces, but it would make sense to give users the flexibility to set this directly. (1, 2, 3, or 4 spaces, or 1 or 2 tabs??).The second case, writer.selfClosingEnd would be useful for sites that want to be HTML 4 strict or want to pave the way for HTML 5.
This only needs to be either
'>'
or' \>'
(or so I assume).References:
- http://docs.cksource.com/CKEditor_3.x/Howto/HTML_Output
- http://docs.cksource.com/CKEditor_3.x/Developers_Guide/Output_Formatting
EDIT:
I am using the D7 version. So I am requesting this in D7 as well.
Comment #4
EvanDonovan CreditAttribution: EvanDonovan commentedSubscribing. "Apply source formatting" is good enough for me, but a way to not hack the module to change the ckeditor settings would be interesting.
Comment #5
marcoka CreditAttribution: marcoka commentedhehe thats what i wanted too. i am working on some small module that uses the "writer" of ckeditor to beatify the code again.
Comment #6
pjcdawkins CreditAttribution: pjcdawkins commentedIs there a workaround for this in D7?
Comment #7
TwoDThere is no true leave-my-indents-alone-workaround for any editor or Wysiwyg version simply because of how the editor(s) are designed.
You can tweak some of the settings affecting what the [re-]generated markup will look like by implementing Wysiwyg's hook_wysiwyg_editor_settings_alter(). Some of the settings have to be applied directly to the active dataProcessor object (as can be seen in wysiwyg/editors/js/ckeditor-3.0.js). To override those, you'd need to set the
customConfig
setting to (giving it the location of a JavaScript file to be loaded when an editor is initialized), and use the custom config script file to hook into CKEditor's instanceReady event and set the formatting rules on the dataProcessor. Wysiwyg also does that, except for the custom config file part since it can send the settings object directly to the instance, so I'm not sure if Wysiwyg's or your event code will run first, but I'm fairly certain yours will be able to override the rules set by Wysiwyg.Comment #8
loopduplicateHi All,
I created a wiki page that shows how to hook into WYSIWYG to change some settings in CKEditor:
https://groups.drupal.org/node/392748
Here's the breakdown:
This was tested on CKEditor 4.3.1 and the WYSIWYG module version 7.x-2.x-dev from 2013-Oct-26.
You'll need to check the "Apply simple source formatting" option in the "Cleanup and output" text format options.
Create module:
Add JS config file:
Cheers,
Jeff
Comment #9
TwoDI'm changing this to a support request since there's nothing we can really do to force CKEditor to leave indents alone, it's simply not designed that way. I hope the earlier comments do at the least show a couple of tweaks you could do to make it less annoying.
Comment #11
MantasK CreditAttribution: MantasK commentedto look look it at least readable I used code from #8 and this js:
Comment #12
davidkronfeld CreditAttribution: davidkronfeld commentedI bumped against the same problem and solved it by installing TinyMCE (went for the v3 - v4 is not yet fully compatible at this time of writing) and the Codemagic plugin (see https://www.drupal.org/project/wysiwyg_codemagic).
The codemagic plugin formats the html sourcecode automagically, making it very readable.
if necessary, define another input style and assign TinyMCE to it, and you're ready to go.
hope this helps.