SemCodeFix: A plugin to display preformatted code in WordPress

SemCodeFix is a WordPress plugin I made to display preformatted code correctly. This plugin can display any type of code, html, text, scripts, etc. Using the plugin is easy, just wrap your text in a code tag from within the WordPress editor. Here’s an example of what it would look like. The code below is Python, its a solution to the Eight queens puzzle.

Code:
def n_queens(n, width):
    if n == 0:
        return [[]] # one solution, the empty list
    else:
        return add_queen(n-1, width, n_queens(n-1, width))

def add_queen(new_row, width, previous_solutions):
    solutions = []
    for sol in previous_solutions:
        for new_col in range(width):
            if safe_queen(new_row, new_col, sol):
                solutions.append(sol + [new_col])
    return solutions

def safe_queen(new_row, new_col, sol):
    for row in range(new_row):
        if (sol[row] == new_col or  # same column clash
            sol[row] + row == new_col + new_row or  # diagonal clash
            sol[row] - row == new_col - new_row):   # other diagonal
                return 0
    return 1

for sol in n_queens(8, 8):
   print sol

To activate/use this plugin, do the following:

1. Place the plugin file in the plugin directory of your WordPress installation and activate it.
2. Copy and paste the CSS into your local.css file of your theme’s directory.
3. Depending on your theme, your might want to change the width value in the div.code_child css style.
4. Any code you have, just wrap it in a code tag from within the editor.

When installed, the plugin will override the native code styles of your theme and display output as above.
Download the plugin file
Download the CSS file

Good luck

Related Articles:

Follow me on Twitter!

Your Ad Here

10 Responses to “SemCodeFix: A plugin to display preformatted code in WordPress”

  1. Anni says:

    Thanks for sharing! I have tried quite a few code plugins and this is the only one that worked for me.

  2. Anthony says:

    What I want to do on my blog, is every few hours take the oldest post and move it to the
    front of the queue, all automatically. Anyone know if there is a plugin that can do this or
    a simple way to set up another plugin to do this (use my own feed perhaps)?
    Thanks.

  3. Cornelis says:

    Great code! Thanks for that. I have one issue with it though and that is that my code doesn’t wrap. I have changed the width value in the div.code_child css file, but it doesn’t wrap it. Any tips to make this work? Thanks!

  4. Pakdoz says:

    Hi, thanks for the plugin. It works fine on my site, http://www.friendstergeek.com.

  5. Brian says:

    Thanks for making the plugin available; it worked perfectly for me.

  6. Jens Törnell says:

    Hi!

    Seems to be a nice plugin. I however does not got it to work fully. My \n is not displayed. Any idea how to fix this? They are visible when plugin is turned off.

    http://www.jenst.se/2007/08/21/wordpress-create-own-more-tag

    (Don’t care about the other code bugs, they are under control.)

  7. Jens Törnell says:

    Hi again!

    I solved my issue by installing preserve code formatting plugin instead. Thanks anyway!

  8. Steve says:

    This is a very lightweight plugin that just does what you need it to and nothing more. GREAT plugin!

    However, I have found three things that it will not preserve, even when wrapped in code tags. These are:

    & nbsp ;
    & gt ;
    & lt ;

    (without the spaces of course)

    I have tinkered around with the code for some time now and I was hoping you can let us know what needs to be adjusted in order to preserve those entities when they are wrapped in code tags.

    Thanks a ton!

  9. Tony Murphy says:

    great plugin, I use it on my html/php course blog

    cheers
    Tony

  10. Jan says:

    Thanks for this wonderful plugin. It does exactly what I needed ! Minified and great. Cheers.

Leave a Reply

Line and paragraph breaks automatic.
XHTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>