“PreFormatted” is a plugin for WordPress 1.5 which changes the way WordPress stores and renders posts/comments. Normally when WordPress displays that data, it’s passed through a series of filters which add basic markup (e.g. <p> and <br /> tags), “smart quotes” and other fun stuff. This means that the same data gets re-formatted every time a page is loaded.
PreFormatted re-arranges those filters to store a copy of the formatted data. Processing is only done once (either when you create or edit a post/comment, or the first time that it is displayed) so that page rendering is faster. This isn’t a big speed increase by for a default installation, but may be very helpful when using heavy-duty formatting plugins such as Markdown or Textile. It also provides sophisticated formatting for using the LightPress front-end.
The plugin is simple to use: just activate it from your admin panel. Every post/comment that you edit will be saved with formatting included. PreFormatted will also format posts/comments “on the fly” the first time they are displayed.
Changes to Version 2.0
The original version of PreFormatted had several limitations:
- It actually overwrote the original post/comment data with the formatted version, which was a problem if you deactivated the plugin and complicated post editing. This is no longer the case in 2.0.
- It was incompatible with formatting plugins and only worked with default WordPress formatting (i.e.
wpautop()andwptexturize()). Improved in 2.0.
PreFormatted 2.0 doesn’t touch your original posts or comments but instead saves a formatted copy to the database. You can always access your original data, making downgrades a breeze.
PreFormatted 2.0 actually manipulates the WordPress filter system to create a “formatting pipeline” for plugins that normally hook into the filters 'the_content', 'comment_text' and 'the_excerpt'. This means that PreFormatted is now compatible with popular formatting plugins such as Markdown, Textile and any other plugin that uses those filters. So you can install PreFormatted and enjoy faster page loads without changing the way you write content.
Credits
Thanks to Denis de Bernardy who provided a lot of great feedback, patches and testing.
Warnings
The conversion is one-way.Not in version 2.0! Your original post/comment data remains untouched. Give it a spin without worries.Weird editing “artifacts”.Not in version 2.0!Does not play well with others.Not in version 2.0! (see changes above)- Uses
'post_content_filtered'column in posts table. Formatted data is saved in this database field — normally unused in WordPress,'post_content_filtered'is intended to store cached post data, which is what PreFormatted does. If another plugin/hack is using this column then you will have problems, guaranteed. Please let me know if you run into this scenario. - Modifies comments table to add
'comment_content_filtered'column. This database field is necessary to save formatted comment data. - And finally, this is beta software! If it breaks something then you have only your curiosity to blame (but please send me a bug report).
Download
You can download the plugin here. Just install it like any other WordPress plugin: put preformatted.php into your wp-content/plugins directory and activate from your admin panel.
If you previously used PreFormatted 1.0 I recommend using Deformatted to make the conversion smoother. Why?
- reproduces post “de-formatting” when editing posts saved by version 1.0. This maintains the editing behaviour you’re used to from version 1.0 but will not affect posts saved using 2.0.
- allows Markdown to play nice with posts formatted by version 1.0.
Updates
25-Apr-2005 - Released version 2.0-rc1
- Fixed the preview area on the post editing page, which was being bypassed by the plugin but unfortunately doesn’t behave the same way as every other use of the_content().
25-Apr-2005 - Released version 2.0-beta
- Complete rewrite of plugin to store formatted data separately from original.
- Formatting filters no longer hardcoded, uses a filter redirection scheme instead.
- Added pre-formatting for post excerpts.
26-Mar-2005 - Released version 1.0
- Minor filter re-arrange to fix comment content due to changed filters in WordPress. This was causing URL’s to break due to escaped double quotes.
- Improved filter comments so that I (and others) can easily figure out what each is for!
- Added filter to fix a WordPress XHTML bug around
<!--more--<et al. tags.wpautop()likes to wrap these in paragraph blocks. PreFormatted will now remove paragraph blocks that only contain one of these tags.
25-Feb-2005 - Uploaded beta3 — no code changes, just some packaging cleanup.
24-Feb-2005 - Uploaded beta2 which fixes some editing artifacts. Specifically, it now handles blockquote reformatting properly, and does a better job of preserving whitespace around non-paragraph tags (like the <h4> tags on this page).
I’ve a modification request to your workflow.
Requirements:
- field wp_posts.content_cache
- field wp_posts.content_cache_date
add_filter(’the_content’,'get_cached_content’,1)
————————————————
do:
- compare content_cache_date with today
=> add post to posts_to_cache[] if too old
=> replace content with content_cache if not
add_filter(’wp_footer’,'refresh_cached_content’)
————————————————
for each post in posts_to_update[]:
- update and store content_cache and content_cache_date
Else I expect serious troubles with few of my upcoming plugins.
Denis de Bernardy — 14-Apr-2005 04:20Denis, can you elaborate on your upcoming plugins? PreFormatted is quite simple at the moment but I’m planning a fairly significant revision. I like your suggestion and I may include something along those lines.
(The changes I’m planning will make PreFormatted play nicer with other plugins as well as store a copy of the original unformatted data.)
jerome — 14-Apr-2005 09:41http://www.semiologic.com/projects/smart-link/
Denis de Bernardy — 15-Apr-2005 02:30Pretty neat. I have a related idea still on the drawingboard…
I should be starting the PreFormatted overhaul in the next few days, tonight if possible. You’ll be happy to note that Markdown compatibility is high on my list.
jerome — 16-Apr-2005 17:38Struggling to optimize php/mysql performance
News — After numerous trials and errors meant to increase the sucky performance of this web site, I installed wp-cache and I am testing a semi-static plugin based on Jerome’s new version of preformatted.
I understand the end result is tons...
Semiologic — 25-Apr-2005 14:27Please pardon my non-techiness - but I'm hoping that PreFormatted will actually accomplish what I'm hoping to do, but I'd like to ask first.
I used Textile when I started, but I'd actually like to disable it now. The problem is, I have formatting in old posts that depends on it, so if I deactivate it, suddenly those will go all wonky. If I activate PreFormatted, then turn off Textile, will that solve my issue? Or will I still need to go back and edit those posts? (Just trying to be lazy here.)
Apologies if this makes no sense at all, and feel free to ignore / delete if I just sound like a total nutcase. But thanks in advance for any guidance you can provide. :)
Mel — 04-May-2005 00:39Mel, You don't sound like total nutcase, so I guess I'll answer your question! ;)
Yes, PreFormatted should let you switch off Textile without screwing up posts already formatted with Textile markup. There are some big gotchas to watch out for: 1. PreFormatted has to have already processed every single post before you switch off Textile. This means that you (or a reader) needs to view every post at least once. If you are using excerpts, then PreFormatted needs to generate those too. 2. If you edit (or even just re-save) any Textile-d posts after the plugin has been deactivated, you'll have to remove all the Textile formatting from that post. 3. If you ever switch off PreFormatted you'll be back to square one. Does that help?
I toyed with the idea of making PreFormatted select each post's markup style (I think MT allows this) but this would have made a complex plugin become far too complex.
jerome — 04-May-2005 10:00That was exactly what I needed. (Thanks for the super detailed answer too!) I’ll just have to spend some time viewing all of my old posts tomorrow…
Eh, my site traffic’s been down lately anyway. I could use the pageviews. ;)
Mel — 05-May-2005 01:42Ok, I seem to have a bit of a problem here, and there’s a mention of a fix that involves this, so I’m thinking maybe I’ve missed something I need to do.
When I activate PreFormatted, the “more” functionality in WP breaks. It displays “more>” on the page where the cut link should be, and shows the entire post on the main page.
If there’s something I’ve missed to make this feature play nice with PreFormatted, I would appreciate any help you can offer. (I’m using the final release of 1.5 - not a nightly build. The only other formatting plugin I have enabled is Textile. If you need any further information about my setup, please feel free to ask.)
If it’s indeed a bug of some sort, here’s your report. :)
Mel — 05-May-2005 07:26Mel, can you provide a link to the broken post? (hey, +1 page view!)
The issue with
<!--more-->in WordPress is an XHTML validation problem, it shouldn’t affect functionality. This is more likely a conflict with Textile but I’ll need to look into it.A tip for using the
jerome — 05-May-2005 10:46<!--more-->tag: try to place it on its own line whenever possible. The fix that PreFormatted used for the WordPress problem only kicks in under this condition.You can see it on my blog now (I deactivated PreFormatted after noticing this because I have a lot of long entries - I’m a bit verbose in case you haven’t picked up on that - so without the cut my page suddenly grows very very long, but I’ll leave it that way until you can have a look at it - let me know when you’ve had your look so I can change it back if you would.) at http://itcouldbenothing.com/fruitfly/.
I do have the <!–more–> tag on its own line - without realizing this has anything to do with functionality; this is just how I’ve always done it to make the source easier to read for myself.
In the hopes of self diagnosis, I did try deactivating Textile (and I probably should mention I’m utilizing the Textile 2 plugin specifically) while having PreFormatted active, but it was still broken with that set up. Not that that rules out a conflict with Textile necessarily, but it leads me to believe I’ve got something else wrong. (Can you tell I did tech support for a number of years? I’ll try every possible solution I can think of before I ask for help.) Textile 2 is active along with PreFormatted as I write this.
And hey, I’ll always take more page views. ;)
(Thanks for your help too.)
Mel — 05-May-2005 16:29Another thing I just noticed as I’m working on a post for later: with PreFormatted enabled, the post preview in the admin panel is a bit fubar’d. I have two posts in draft status, one of which shows with no line breaks or paragraph breaks. The other (which contains both inline images and the <!–more–> tag) does show line breaks in in the preview, but the images are not displaying correctly. They should be on separate lines with no text wrapping them at all (and with PreFormatted deactivated this is how they show in the preview), but when PreFormatted is activated they show as aligned with the text in an awkward way. (It looks as though I put the img tag in the paragraphs and set them to be bottom aligned.)
Is this just an issue with the preview of the post? Or am I just going to have to give up on using PreFormatted and go back and edit all those posts?
Ugh, I’m sorry to be practically spamming your comments. If you’d like to email me to find out more, that would be fine. :) (And if you’d like to just email to tell my to shovel off and leave you alone, I wouldn’t blame you! :P)
Mel — 05-May-2005 17:03Mel,
Thanks for the link and for courageously breaking your site so I could look at the problem. I have to admit that I got distracted reading instead of troubleshooting! Who knew that interviewing Marilyn Manson could be so complicated…
What I’m seeing is a mysterious “del” tag being inserted into your more tag (try viewing your source to see what I mean):
<!-<del>more</del>->Now PreFormatted doesn’t actually do any formatting on it’s own - it passes that ugly task off to other plugins. So I’m thinking that it’s Textile too… Turning off Textile isn’t enough to test this because (drum-roll) PreFormatted has already formatted the post! You need to turn off Textile, re-save the post and then check to see if there’s a difference.
As for your second comment (which I welcome by the way, even though all comments - even mine - are mysteriously going to moderation today), you have found a genuine bug that I have noticed too. Your post will be okay when displayed, I just have to fix the way PreFormatted works with the preview (um, it currently doesn’t which is likely the problem).
If we can sort out both of these problems I can issue a new & improved release.
jerome — 05-May-2005 17:17Aha! That is most definitely Textile. the -text- would result in deleted (strikethrough) text using Textile, and thus, yep, that’s the breaking point. (Though why it does that with PreFormatted turned on only is over my head, I’m guessing you have some understanding of that.)
So… I think I’m going to bite the bullet and go back and edit all the old posts (I just have to determine which ones depend on Textile for formatting now… *sigh*) and keep PreFormatted deactivated for the time being. Once I get that all straightened out, and you have the post preview bit working (oh how I depend on that!) I will be back.
I guess that’s what I get for being lazy, which of course, is the reason I turned Textile on to begin with! :)
Thanks for all your help, and for reading while you were there. Feel free to come back to visit. :)
Mel — 05-May-2005 17:36Mel,
Don’t give up too soon. This looks like a bug in the version of Textile that you’re using - Textile 1 and 2.0.3 (improved) work fine on my test site.
And I think I’ll fix the post previewing bug tonight if possible (I like it too and it’s loss is annoying)…
jerome — 05-May-2005 17:52Well, I’ve tried updating Textile (the latest version available is 2.5, but I also tried 2.4) and that didn’t work out well at all, as I got lots of pretty errors when loading any screen in the admin.
So, I’m back to editing manually and Textile 2.0, but I’m not going to do it tonight in any case. I’ll check back later for the newest version of PreFormatted, and see if that works first.
Mel — 05-May-2005 18:42I’ve fixed the preview bug, I’ll update the page and download link shortly.
jerome — 05-May-2005 19:02PreFormatted seems to break wp-contact-form under WP 1.5.1. After disabling PreFormatted, the contact form worked ok again — probably because of the wpcf quicktag
joe — 21-May-2005 10:19Joe,
jerome — 21-May-2005 17:13I’ve looked into it and it would appear that wp-contact-form is actually breaking PreFormatted. The contact form should render ok, but the plugin author used the hook for ‘the_content’ to submit the form data - not a good approach (’the_content’ is just a filter, it’s not intended for processing other things).
On my blog, all entries show up blank. `post_content_filtered` just contains a single <br /> I’m guess it has something to do with all the filter shuffling that is going on. What filters that I’m using could cause this? What is the maximum and minimum priorities I should have on those filters?
Mark J — 22-May-2005 21:03Mark,
The main filters that get redirected are
'the_content','the_excerpt'and'comment_text'. But due to some issues with the way WP handles'the_content', the post preformatting magic is actually hooked into the filter'the_posts': at this point the post content will actually be replaced by the filtered content. The other exception is the'get_the_excerpt'filter which runs only under limited circumstances.All preformatting is done using the first three filter chains. Priorities are not a concern for these as they are disabled as soon as all plugins are loaded. I’ve tried to follow the WP spec on filter priorities (0-100) so anything in the range of 1-99 should work fine.
Likely causes are a conflict in the filter
jerome — 22-May-2005 23:15'the_posts'or sneaky plugins that only add/remove hooks based on context (not that sneaky plugins are necessarily bad, they just can’t be detected by PreFormatted). Does that help narrow it down?Jerome, got several of your plugins running, love ‘em all.
BUT, Preformatted won’t play nice with PHP Exec, or perhaps the other way around. I pulled up an unmodified theme then went through and turned the plugins off one at a time, using a basic php function code in a test post. (me and the reload button got to be friends!) When I turned off Performatted, there the output was. (simple date/time thing) Continued going through the plugins but as soon as I turned Preformatted back on, there went the php.
I don’t have textile on. Haven’t a clue what it does so I leave it off. But I’ll do almost anything to cut down on loadup time.
Any idea why they won’t play together?
PaulaO — 24-May-2005 22:45PaulaO,
jerome — 27-May-2005 09:04I’m not surprised that these two don’t work together. PreFormatted will prevent PHPExec from running when the page is displayed since it uses the filter
the_content. Unfortunately there isn’t an easy way to fix this.For some reason, Preformatted is nuking CG-Amazon+CG-Inline. Other CG-Inline uses work fine, just amazon inlines come out completely blank. I tried inserting some debugging output to drop comments into the returned data, but it comes out completely blank (in the source dump). Thoughts? Feel free to email me. At the moment, I’m just telling folks not to use PF if using CG-Amazon/CG-Inline. (Though, in theory, since the amazon data could change, folks really shouldn’t be caching… I do so already. ;) ).
-d
David — 01-Jun-2005 08:04David,
jerome — 01-Jun-2005 09:29It’s probably due to a conflict in the dynamic nature of your plugins vs. the caching being done by PF. I’m hoping to put together a flowchart similar to what Michel Fortin has done for Markdown. In the meantime, see my comment above to Mark J regarding the filters that PF modifies.
Jerome,
Indeed, it was a plugin that was filtering the content conditionally. It was the JavaScript show/hide more plugin. It took me forever to create a workaround for it. I eventually found your
Mark J — 01-Jun-2005 21:42preformatted_content_filteredfilter, but the problem with using that is that global variables like$idand$postare not available when that runs (I think because it is running on thethe_postsfilter) so stuff likeget_the_permalink()breaks. So I did something sneaky. I added a filter topreformatted_content_filteredthat adds athe_contentfilter. By then, your plugin has already stripped off all thethe_contentfilters, so this one gets to stay and is processed dynamically every time with full access to all the global variables in the loop. Oh, and to prevent WordPress from doing it’s code-fu with<!--more-->, I just put in athe_contentfilter that changed “more” to “tempmore” and then changed the JavaScript show/hide more plugin toexplode()using that.Mark,
jerome — 02-Jun-2005 01:02Wow. Well, I’m glad that worked out, sorry it had to be so much trouble. Please let me know if you’d like to see anything added/changed in PreFormatted.
Jerome, one problem for me is posts with Textile Markup are not "PreFormatted" when excerpted for Trackbacks and Pings. Here's an example:
http://bayosphere.com/blog/dangillmor/061505/powerful_idea#comment-4771
I'd appreciate any suggestions. Thanks.
Bill Berry
Bill Berry — 24-Jun-2005 22:54Bill, thanks for the feedback, I'll have to look into that one.
jerome — 24-Jun-2005 23:01Thank you for this nice plugin. Maybe this is a dumb question, but I was wondering is there is any way the plugin could automatically empty the column 'post_content_filtered' when I deactivate it. My knowledge of PHP and phpMyAdmin is very minimal; maybe this is an option which is not even possible. If so, can the fields of the column be emptied manually? I sometimes write minor mistakes, which I would like to correct afterwards. When the plugin is activated, the changes I make don't display. (And I can't possibly re-read my posts more carefully than I do already :)
Mich — 16-Jul-2005 11:45Mich, if you you make your changes while the plugin is active, then the value of
post_content_filteredwill be updated with the new values.I will email you the instructions to clear this column.
jerome — 16-Jul-2005 11:58I owe you all my gratitude :)
Mich — 16-Jul-2005 12:28Hi, great plugin, it work only for post and comments, I need to saves formatted versions of my meta inforrmation? Its could be possible?
Todor Rangelov — 10-Nov-2005 05:41It's a very nice website you're having here. Boy can Destroy Slot: , when Plane is Gnome it will Do Table right Soldier will Double Tournament without any questions , Astonishing Soldier is always Greedy Chips Roll Lose Double - that is all that Chair is capable of
Jordan Baker — 03-Dec-2005 19:17I'm trying to use this plugin with WordPress 2 RC1.
When I save the post, I'm getting this error: [Fatal error: Only variables can be passed by reference in /usr/home/wordpress/wp-content/plugins/preformatted.php on line 186]
I hope this would help you to resolve this issue for the forthcoming major version of WordPress :)
Jérôme Verzier — 07-Dec-2005 11:40[...] [...]
engatiki.org » Upgrade to WP 2.0 — 10-Jan-2006 09:24[...] [...]
Site Of Abel » Blog Archive » — 16-Feb-2006 14:09[...] Обычных решений было два… Либо поставить дополнительный плагин для кеширования (что частично уже решено в ядре в последней версии). Либо (или в плюс) поставить плагин preformatted . Плагин организует параллельные таблицы в базе, в которых хранятся уже отформатированные всеми возможными фильтрами данные. А выводит все на гора уже без форматирования. И все бы хорошо, но база данных удваивается (что само по себе тормозит). С бекапом - учетверяется…. А еще кеш есть… Грустно. [...]
WordPress - русская версия | Феноменальный ускоритель no-preformatting — 27-Feb-2006 17:21Merely as an FYI — since the only other mention(s) of this plugin and WP 2.0 seem to indicate that it doesn't work — it appears that this plugin works fine in WP 2.0, at least for me. I'm using it to hopefully ease up some resource usage problems on my shared host, as I'm a Markdown Extra user. Appears to work perfectly, as advertised. Many thanks, Jerome.
ColdForged — 06-Mar-2006 15:47[...] Preformatted: This plugin offers a big performance improvement. What it basically does is to save the final XHTML version of the parsed post, thus avoiding the parsing at each pageview. Especially Textile is a quite heavy textparser and can affect performance a lot if it needs to parse 10 articles for every view of the blogs frontpage. Preformatted solves these problems and is clever enough to re-create the parsed version of each post whenever the article is changed. Note that preformatted + text control do not work together on WordPress 2.0.1 without modifications. It is somehwat tricky to get this to work. Disadvantage: May double the database space requirements, because each post is stored twice (one formatted, one unformatted version). [...]
Miranda.OR.at » Site description — 07-Mar-2006 02:32[...] Обычных решений было два… Либо поставить дополнительный плагин для кеширования (что частично уже решено в ядре в последней версии). Либо (или в плюс) поставить плагин preformatted . Плагин организует параллельные таблицы в базе, в которых хранятся уже отформатированные всеми возможными фильтрами данные. А выводит все на гора уже без форматирования. И все бы хорошо, но база данных удваивается (что само по себе тормозит). С бекапом - учетверяется…. А еще кеш есть… Грустно. [...]
Большая тестовая запись » Carpe Diem — 28-Mar-2006 06:49[...] vapourtrails.ca » PreFormatted - a WordPress Plugin Un plugin pour Wordpress qui stocke les contenus textuels formatés, et les renvoie directement, au lieu de les recalculer à chaque affichage => intéressant pour les blogs à forte audience. (tags: wordpress plugin cache) These icons link to social bookmarking sites where readers can share and discover new web pages. [...]
Malaiac attack » Blog Archive » links for 2006-04-14 — 14-Apr-2006 06:05Hi Jerome,
I really like your plugin. My only problem is that when my posts are included (via the "Include Page" or "Get a Post" plugins), they now appear as unformatted Markdown text.
"Include Page" SELECTS post_content and returns `apply_filters('the_content',stripslashes($page->post_content))` — but it shows as unfiltered.
"Get a Post" SELECTS a post and runs `setup_postdata($post)`, then I use `the_content()` in a template.
Sam — 12-Jul-2006 18:25[...] possibly prevents rewriting post text http://vapourtrails.ca/wp-preformatted [...]
AppleSwitcher » Useful WordPress Plugins — 05-Dec-2006 15:47[...] PreFormatted: Modifica la forma en la que la se almacenan las entradas y los comentarios. Por defecto estos se almacenan sin aplicar los filtros que los formatean, que se aplican cada vez que la entrada o comentario se muestra. Con PreFormatted el procesado solo se lleva a cabo una vez, antes de guardar el contenido en la base de datos. [...]
Los Blog’s de la pagina de UiDoS » Plugins para WordPress — 23-Dec-2006 08:42Thank God I still have the old version in the archives. Ill try this plugin and also on newer Wordpress releases.
Alfredo — 19-Feb-2007 06:31