Archive

Posts Tagged ‘TinyMCE’

Visual Code Editor 1.2.5

March 4th, 2010

I’ve updated Visual Code Editor. Not so much an upgrade, but tested it out with SyntaxHighlighter Evolved 2.3.8 and WordPress 2.9.2.

SyntaxHighlighter Evolved fixes a lot of the problems that VCE also fixed (for SyntaxHighlighter Plus 1.x). But VCE still comes into play when you want to use tinyMCE (the post editor) in WordPress.

  • Adds `<pre>` & `<code>` to block format menu
  • Allows extra attributes for compatibility in some syntax highlighters (ie, `<pre lang=”php” line=’5′>`)
  • Unescape WP’s double escaping of & (not needed with SHE)
  • Allows iFrames in the post
  • Support for syntax highlighting in comments
  • Removes extra `<pre>` tags around SyntaxHighllighter Plus’s sourcecode blocks

I tested it out with SHE and they both play very well together. Although the fixes in VCE are no longer needed, it still adds some functionality to the Visual Editor. Since nothing broke, I’m not going to fix it (remove the fixes). This allows its continued use in other client side syntax highlighters.

Go get it –> http://wordpress.org/extend/plugins/visual-code-editor/

Also, I highly recommend SyntaxHighlighter Evolved.

Visual Code Editor , , , ,

ColdFusion function: create tinyMCE instances

March 31st, 2009

As promised, I am releasing the CF function I use to display tinyMCE instances. It can handle multiple languages, multiple instances per page, and of course compression.

It’s somewhat basic right now. I set up defaults for most end-clients, meaning its easy to use and familiar feeling. I came to this configuration after working with clients for two years – listening to their complaints and slowly molding the defaults to what is here now.

The simplest incarnation is:

<cfoutput>
#application.formutils.tinymce(content=read.bio)#
</cfoutput>

This assumes you cached the CFC into an application variable called ‘formutils’, and a query named ‘read’ with a field called ‘bio’. That will generate the base code (put into the htmlhead by default), create the textarea named ‘content’, set up modified defaults for tinyMCE and then display it.

But you can get fancier:

<cfoutput>
#session.utils.tinymce(
	content=read.rightcolumn,
	element="rightcolumn",
	cssfile="/includes/css/common.css,/includes/css/tiny_dyn.cfm?csswidth=210px",
	resizing=false,
	loadbase=0
)#
</cfoutput>

That one will create a textarea with name and id of ‘rightcolumn’. It will also use specific css files. If you notice that last css file is a cfm page that dynamically creates the width of the page. This is awesome for giving the editor a real-time view of their page. Then it turns resizing off. Finally, with loadbase=0, the base of tinyMCE will not be loaded (this example is for a secondary tinyMCE instance in the same page).

Most of the defaults can be overridden with arguments as demonstrated above. However this function is not all-encompassing of tinyMCE’s many attributes. If you need more customizability, feel free to fork the git project, or simply ask me for the attribute you need inserted.

You can get this CF function directly from github: http://github.com/WebVeteran/cf-tinymce

Bonus example

A multilingual coldfusion application using tinymce for translations. One instance is the english, the other is spanish. Both use a very simple editor. It’s actually the advanced editor configured to mock the simple editor, but with a few extra buttons.

<cfoutput>
<tr>
	<td>
		#application.includes.tinymce(
			content=read.en,
			element="en",
			csswidth="444px",
			resizing=true,
			theme='advanced',
			theme_advanced_buttons1 = "bold,italic,underline,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,|,bullist,numlist,|,undo,redo,|,code,cleanup",
			theme_advanced_buttons2 = "",
			theme_advanced_buttons3 = ""

		)#
	</td>
	<td>
		#application.includes.tinymce(
			content=read.es,
			element="es",
			csswidth="444px",
			resizing=true,
			theme='advanced',
			loadbase='0',
			language='es',
			theme_advanced_buttons1 = "bold,italic,underline,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,|,bullist,numlist,|,undo,redo,|,code,cleanup",
			theme_advanced_buttons2 = "",
			theme_advanced_buttons3 = "",
			gecko_spellcheck = "false"
		)#
	</td>
</tr>
</cfoutput>

Output is:

two tinymce instances

two tinymce instances - click to view larger

CF TinyMCE , , , , ,

TinyMCE CF GZIP 1.0

February 9th, 2009

TinyMCE CF GZIP is a ColdFusion based Javascript Concatenater, Compressor, and Cacher for TinyMCE.

This file compresses the TinyMCE JavaScript using GZip and enables the browser to do two requests instead of one for each .js file. From nearly 100 requests to 2, about 400KB to 80.

It is also a single file install. The current official TinyMCE ColdFusion Compressor requires a JAR file installed. But this one does not! Just drop the CF in, modify the TinyMCE js to use this file, and you’re done!

 

TinyMCE CF GZIP

TinyMCE CF GZIP

Live demo

Later today the source will either be on sourceforge or github. Stay tuned!

TinyMCE CF GZip , , , ,

Visual Code Editor v1.0

November 18th, 2008

Visual Code Editor modifies WordPress’s behavior so that code format is preserved when using the visual editor. It will work with any syntax highlighter that accepts encoded (or escaped) syntax.

Download the plugin: http://wordpress.org/extend/plugins/visual-code-editor/

WordPress is really nice. But it mangles syntax in posts. I set out to end that with a non source-code-editing method: a plugin!

The problem in WordPress comes in when you edit your post twice. When you load that post again, WP converts ampersands into “&”. Which is nice. But if you edit that post again, WP re encodes ampersands again. Giving you “&”. Want to guess what happens if you save and load it again? :)

Now lets compound that with the visual editor, which automatically encodes for you as you type or paste. That only accelerates the process. And the fault here is with WP when it loads the post. Not with TinyMCE, at all.
Lets make matters even worse. WP’s default settings for TinyMCE is really screwy. It’s horrible for programmers who want to blog.

  • Users have to switch to HTML or TEXT views to insert <pre> or <code> tags.
  • TinyMCE does not allow unknown attributes for tags like <pre line=”1″>.

That may sound really picky. But most syntax highlight plugins require either <pre> or <code> and to use special attributes in them to display properly. Some require the syntax to have all entities escaped, some require the opposite. What a freaking nightmare. So I set out to end this nonsense.

Enter Visual Code Editor. It’s a plugin I wrote for WordPress. Visual Code Editor makes it possible (and trouble free) to post and edit code snippets in wordpress’s visual editor.

  • Adds <pre> & <code> to block format menu
  • Allows extra attributes for compatibility in some syntax highlighters (ie, <pre lang=”php” line=’5′>)
  • Unescape WP’s double escaping of &
  • v1.1: Removes extra <pre> tags around SyntaxHighlighter Plus’s sourcecode blocks
  • v1.1.1: Tested with WordPress 2.7

And the nicest thing is… it’s a plugin! You don’t have to go around editing WP’s base installation. Download, extract, upload, activate, done.

Coupled with the SyntaxHighlighter Plus plugin, you get results like this:

syntax highlight

Syntax highlighter Plus runs through javascript on the client and expects the code to have entities encoded. Thanks to my plugin and TinyMCE, we’re golden. I chose Syntax highlighter Plus for a few reasons.

  • it’s the easiest to use and is smart.
  • It runs in javascript, search engines do not see tons of inline css muddying the page.
  • The page also downloads faster because of that.
  • The ‘copy to clipboard’ does not require flash.

All you have to do is create a [/sourcecode] block, select the sourcecode block, select Preformatted from Tiny’s format menu, then paste in your code. It should look like this:

syntax highlight   

The Preformatted area tells TinyMCE to leave the formatting the heck alone. makes Syntax highlighter Plus do it’s magic on the viewer side. And you can still edit all of your code in the visual editor. Awesome!I also left the door open for other syntax highlighters, which instead of using , use <pre lang=”xxx” [line="5"]> or even <code>, etc.   

Feel free to download the plugin, which is now in the WordPress PlugIn Directory! Yippee I learnt how ta use SVN today! http://wordpress.org/extend/plugins/visual-code-editor/

Plugins that failed to help

I did my homework before writing this plugin. I tried all of the following. All of which failed in one way or another.

  • Chili Code Highlighter
  • CodeHighlighter
  • Developer Formatter
  • Disable wpautop
  • Editor Extender
  • EmbedIt
  • Google Syntax Highlighter for WordPress
  • Preserve Code Formatting
  • Raw HTML capability
  • Text Control
  • TinyMCE Entities Patch
  • Code Snippet
  • Dean’s Code Highlighter
  • Highlight Source Pro
  • iG:Syntax Hiliter
  • Sniplets
  • Snippet Highlight
  • WP-CodeBox
  • WP-Syntax

Visual Code Editor , , ,