Category Archives: Visual Code Editor

Visual Code Editor 1.2.5

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 with WP-Codebox

This is a test using the Visual Code Editor plugin with the WP-CodeBox plugin.

Original code:

	<Tr>
		<td style="background-color:##598CB5;color:white;font-weight:bold;">
			#l1title#
		</td>
		<td rowspan=16>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
		<td style="background-color:##598CB5;color:white;font-weight:bold;">
			#r1title#
		</td>
	</tr>
<!--- ORDER --->
<cfhttpparam name="x_invoice_num"         type="formfield" value="#invoice_num#" >
<cfhttpparam name="x_description"         type="formfield" value="ScenicMesa.com online order">
<cfloop list="#x_line_items#" delimiters="#chr(9)#" index="i">
	<cfhttpparam name="x_line_item"       type="formfield" value="#i#">
</cfloop>

And here is WP-CodeBox enabled:

Rendering of WP-Codebox
Rendering of WP-Codebox - I took this screen capture just before turning deactivating the plugin.

Visual Code Edior allows for syntax and code editing right in WordPress’ invocation of TinyMCE. Therefore, all html entitied are escaped. As you can see this sometimes does not work with WP-CodeBox since it expects non-escaped code. This is why WP-CodeBox made it on my “Plugins that failed to help” list.

Now for SyntaxHighlighter Plus, which, on the other hand expects escaped code. And so it works well when editing code in visual mode of the WordPress post editor:

[sourcecode language=”coldfusion”] <Tr>
<td style="background-color:##598CB5;color:white;font-weight:bold;">
#l1title#
</td>
<td rowspan=16>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td style="background-color:##598CB5;color:white;font-weight:bold;">
#r1title#
</td>
</tr><!— ORDER —>
<cfhttpparam name="x_invoice_num" type="formfield" value="#invoice_num#" >
<cfhttpparam name="x_description" type="formfield" value="ScenicMesa.com online order">
<cfloop list="#x_line_items#" delimiters="#chr(9)#" index="i">
<cfhttpparam name="x_line_item" type="formfield" value="#i#">
</cfloop>[/sourcecode]

Visual Code Editor 1.1 – valid xhtml

Gremmie noticed that Syntax Higlighter Plus adds it’s own <pre> tag when outputting to page. That creates a nested <pre> tag which is not valid xhtml. So I fixed that with 1.1. Using <pre> in visual mode is still required. The fix is to remove the extra <pre> on output to page.

Also updated are the instructions of how to post code snippets:

  • In visual mode, create a [sourcecode language=”xxx”][/sourcecode] block
  • Select the sourcecode block
  • Select Preformatted from TinyMCE’s format menu
  • Paste in your code

    Log into your WP Admin and update the plugin for the fix!

    Visual Code Editor v1.0

    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 language=”xxx”][/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. [sourcecode] 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 [sourcecode], 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

    WordPress Plugin, Visual Code Editor, posts and edits code snippets in wordpress’s visual editor

    I will be moving my blog from blogCFC to WordPress. So I have it installed and played with skins and syntax highlighting… which is quite lacking.

    The problem comes in when you edit your post twice. When you load that post again, WP converts ampersands into “&amp;”. Which is nice. But if you edit that post again, WP re encodes ampersands again. Giving you “&amp;&amp;”. 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 init for TinyMCE is really screwy. Looking at the code you’d think they were rocket scientists. But… dang it… the defaults are 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

    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 language=”xxx”][/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. [sourcecode] 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 [sourcecode], 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

    Here are the plugins that I am currently running:

    WHEW! That’s enough blogging for today. I gotta get some work done!