Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am using the CodeColorer plugin to display source code in my WordPress. I am trying to have my code indented so that it displays properly on the website. However, when I try to add the following code to the WYSIWYG editor:

[cc lang="csharp"]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LittleSoftwareStats
{
    public static class Config
    {
        public static bool Enabled { get; set; }

        internal static string ApiUrl
        {
            get
            {
                UriBuilder uri = new UriBuilder((Config.ApiSecure) ? ("https") : ("http"), Config.ApiHost, Config.ApiPort, Config.ApiPath);

                return uri.ToString();
            }
        }
        internal static string AppId { get; set; }
        internal static string AppVer { get; set; }

        internal const string ApiHost = "stats.yourwebsitehere.com";
        internal const int ApiPort = 80;
        internal const bool ApiSecure = false;
        internal const string ApiPath = "api."+ApiFormat;

        internal const string ApiFormat = "json";
        internal const string ApiUserAgent = "LittleSoftwareStatsNET";
        internal const int ApiTimeout = 25000;
    }
}
[/cc]

When I update it, the code then becomes:

[cc lang="csharp"]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LittleSoftwareStats
{
public static class Config
{
public static bool Enabled { get; set; }

internal static string ApiUrl
{
get
{
UriBuilder uri = new UriBuilder((Config.ApiSecure) ? ("https") : ("http"), Config.ApiHost, Config.ApiPort, Config.ApiPath);

return uri.ToString();
}
}
internal static string AppId { get; set; }
internal static string AppVer { get; set; }

internal const string ApiHost = "stats.yourwebsitehere.com";
internal const int ApiPort = 80;
internal const bool ApiSecure = false;
internal const string ApiPath = "api."+ApiFormat;

internal const string ApiFormat = "json";
internal const string ApiUserAgent = "LittleSoftwareStatsNET";
internal const int ApiTimeout = 25000;
}
}
[/cc]

I have also tried replacing the spaces with  , and 	 and the actual TAB character. If I add the TAB character in the Text editor then it will stay but once when I switch it to the Visual editor then it is all removed. I was wondering if anyone knows a trick to keeping the code indented or if there's someway to fix it (without modifying the CodeColorer plugin)?

share|improve this question
1  
TinyMCE isn’t made for custom HTML formatting. You should avoid it completely. Use the HTML editor, now misnamed Text. –  toscho Feb 25 '13 at 0:10
    
Or you can use custom post meta; I do that to have absolute control and to ensure plugins don't interfere. Check out pea.rs which uses post meta well for this purpose. Adding syntax highlighting via alexgorbatchev.com/SyntaxHighlighter is a piece of cake. –  Matthew Boynes Feb 25 '13 at 1:24
add comment

1 Answer

It looks like I figured it out. I installed SyntaxHighlighter Evolved and SyntaxHighlighter TinyMCE Button. When I select the code and use the TinyMCE button to highlight it, the spaces seem to stay. This also works in both TinyMCE's Visual and Text editors.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.