OK, here's another little HowTo : Update the Styles dropdown with your own styles...
Get this:
http://ckeditor.com/addon/stylesheetparser
and this:
http://ckeditor.com/addon/stylescombo
Put them under here:
/manager/assets/components/ckeditor/ckeditor/plugins
as /stylesheetparser and /stylescombo
Create a very simple style sheet. I called mine 'ckeditor.css' and here's a sample from it:
p.emphasis1 {
color: #75abff; }
h2.pagetitle {
font-size: 160%;
margin-top: 30px;
text-align: center; }
It's important to note that what you're doing is creating a manager-only style which hints at what your real style might look like. This doesn't need to be the actual site style.
Now you need to edit /manager/assets/components/ckeditor/modx.htmleditor.js
Look for the block that begins:
MODx.ux.CKEditor = Ext.extend(Ext.ux.CKEditor, {
editorConfig: {
These are editor parameters that get passed to CKEditor instead of using the app's config file. Currently the last line is
coreStyles_strike: {element: 's', overrides: 'strike'}
Add a comma to that and one more line:
contentsCss: MODx.config['site_url'] + '/assets/templates/ckeditor.css'
Note that's just my location for the CSS, change as you wish.
Put your CSS in the location specified above.
Now go to Manager > System > System Settings. Open the ckeditor settings. Set the key
ckeditor.extra_plugins to value
stylesheetparser,stylescombo.
You should now be able to refresh a resource and check the Styles dropdown to see your styles.
Let's connect the dots.
- You put scripts on your system
- Created CSS
- Placed it in your environment
- Told the ckeditor addon where to find your CSS
- The addon tells the stylesheet parser where to find the CSS
- You told the ckeditor addon to load the ckeditor plugins
- The stylesheet parser plugin parses your CSS into internal code
- The internal code is then used by the stylescombo plugin to populate the plugin
Notes (subject to change):
- If you don't see the Styles list change: You may have misplaced the CSS, or you may have CSS which gets filtered out. See below. I recommend you use my example to start and then customize one step at a time, refreshing your resource page after each step to ensure the changes are good.
- Notice how the p.foo style applies the foo class to the p tag. It's not pretty but that's the pattern. This is another reason why it wouldn't do to load your default styles.
- In order to parse the CSS, the stylesheetparser seems to actually load it. Don't put common styles in there like 'body' or these will override your Manager styles. The styles are not added to the Styles list but the CSS is active.
- You'll see that the Styles list shows the style name using the style. It does this obviously because it has loaded the style sheet. Again, don't use style names which conflict with Manager styles or the moono skin used by the ckeditor addon.
- stylesheetparser/plugin.js does use regular expressions to filter styles from your CSS before parsing into that internal format. There is a skipSelectors filter to filter Out styles ( /(^body\.|^\.)/i ), and a validSelectors regex to filter In styles ( /\w+\.\w+/ ).
- Don't modify that script to change the values. Use the config settings as above. Add values:
stylesheetParser_skipSelectors: (your regex),
stylesheetParser_validSelectors: (your regex)
Frankly, I tried using my own expressions and was unsuccessful. The .js has examples at the bottom of the file. More info is here. There you'll see those notes how the CSS parser is limited (doesn't allow for nice names and other issues), and how that has prompted some to skip the parser and write their own style info direct for stylescombo.
- As an enhancement to the ckeditor addon, I think more of the editorConfig values should be moved out of the .js and put into system settings - I'm sure that's already in the roadmap. It's probably safe to say the keys mentioned here could be added.
- You don't need the CSS, you can create the intermediary files yourself.
- On that page you'll also see that there is a way to clear the default list of styles from the dropdown before adding your own. To do that here, add this editorConfig value right before contentsCSS:
stylesSet: [],
- Conversely, the p.foo styles described here are block styles. I don't know yet how to define inline styles like 'strong'. So unless someone posts a solution, you may not want to remove the defaults unless you really never use them.
I said in my last note that I was uncomfortable with the regex, etc. Now that I've done this and understand it, I don't have a problem with it. YMMV