• I want to remove the textile plugin from my set of installed plugins so that I can more easily and completely control the formatting of my posts with a WYSIWYG editor. However, I have a large supply of back-posts that are formatted in textile, and I don’t want to lose that formatting.

    Is there a way to go over the whole database of posts AND comments and textile-ize them into HTML in the database, thereby removing the requirement for me to maintain textile formatting for the future?

Viewing 6 replies - 1 through 6 (of 6 total)
  • I have also been looking for a similar application for a very long time. So far nothing!

    I would also like to use a WYSIWYG Editor in the future, but fear that all my older posts will be unusable. This is a particular problem for some websites I set up using wordpress as a CMS.

    Make a database backup before you try this.

    I put this into my-hacks.php (and it is indeed a hack):

    <?php function crs_convert_textile() {
    global $wpdb;
    $postsout = $wpdb->get_results("select ID from wp_myblog_posts where ID > 0;");
    foreach ($postsout as $thispost) {
    $thiscontent = $wpdb->get_var("select post_content from wp_myblog_posts where ID = $thispost->ID;");
    echo "$thispost->ID<br />n";
    $newcontent = apply_filters('content_save_pre',textile($thiscontent));
    $wpdb->query("UPDATE wp_myblog_posts SET post_content = '$newcontent' WHERE ID = $thispost->ID;");
    }
    } ?>

    (Replace “wp_myblog_” with the prefix for your own databases.)

    Then I added this to my 404 page before the footer:

    <?php crs_convert_textile(); ?>

    Now browse to a page that does not exist. If it ends in a timeout error, scroll down to the bottom of the page that was returned and note the last number that is listed; in my case it timed out after 30 seconds on post 221. Then I updated this line:

    $postsout = $wpdb->get_results("select ID from wp_myblog_posts where ID > 0;");

    To be like this:

    $postsout = $wpdb->get_results("select ID from wp_myblog_posts where ID > 221;");

    Repeat until you are through all your posts.

    I didn’t test this at all, other than using it on my own site. I did do a backup before I started. I didn’t use this on comments or excerpts or anything like that. It does seem to have worked. If you have posts that show up with other errors, make note of their number and change those manually (I had one with a complicated escaped table that didn’t make it through and I had to manually reformat that).

    When finished, turn off your Textile plugin. I used the Textile 2.6 plugin that is compatible with WP2, and I was running WP2.0.2 when I did this (this afternoon).

    Caveat lector! This is scary and I’m glad it worked for me; I hope it works for you but this is a wholesale swap of a lot of content.

    Oh, and then pull it out of your 404 page post-haste. You don’t want anybody else doing this again after you did it once (unless you trust Textile to reformat HTML; I don’t).

    Thread Starter offline

    (@offline)

    csebold’s solution is an idea, to be sure, and it’s one I’ll consider, but I’m a bit leery of using something that’s that much of a hack (no offense, csebold). Has anyone got any other ideas, while on this track?

    csebold’s script mostly worked for me (WP 2.0.3, Textile 2, Huddled Masses’ version). The only problem I had had to fix manually had to do with single quotes: MySQL choked at times when they occurred — because they weren’t escaped.

    Thanks, csebold!

    Um, not to seem obtuse, but how would you do this to comments and excerpts and stuff? I’m having major textile issues at the moment – for some reason it has entirelay stopped processing image tags and is completely breaking my site.

    Thanks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Convert textile markup to HTML in the database’ is closed to new replies.