• daath

    (@daath)


    Hello!

    I was just wondering, when I write code snippets with the pre-tag the contents gets addslashes() or at least ” gets escaped – This is not the case with for example the code-tag…
    Any thoughts on how I remove the escapes using the pre-tag?

    Result when using code-tag:

    printf( “hello” );

    Result when using pre-tag:

    printf( \”hello\” );

    I’m using WP 1.5 final!

    Thanks ??

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter daath

    (@daath)

    No takers?

    gaemon

    (@gaemon)

    This is due to the last line of wpautop():
    $pee = preg_replace(‘!(<pre.*?>)(.*?)</pre>!ise’, ” stripslashes(‘$1’) . clean_pre(‘$2’) . ‘</pre>’ “, $pee);

    you can fix this by:
    $pee = preg_replace(‘!(<pre.*?>)(.*?)</pre>!ise’, ” stripslashes(‘$1’) . stripslahes(clean_pre(‘$2’)) . ‘</pre>’ “, $pee);

    hope this helps.

    Thread Starter daath

    (@daath)

    It worked like a charm, thanks! Do you know if they are fixing this in coming releases?

    mlambie

    (@mlambie)

    At the risk of being pedantic, the code should read:

    $pee = preg_replace('!(<pre.*?>)(.*?)</pre>!ise', " stripslashes('$1') . stripslashes(clean_pre('$2')) . '</pre>' ", $pee);

    The second stripslashes was originally stripslahes. Easy typo to make. This works well for me.

    Sorry chaps,
    may you tell me which file to apply these changes?

    If PHP had namespaces that matched the filenames, it wouldn’t be such a pain to find out what functions were in which files.

    For the benefit for anyone else that finds this thread, I found the wpautop function in functions-formatting.php.

    And the fix worked.

    I just moved to wordpress. This is immediately the problem I encountered. The solution provided by above works for the problem of appearing backslashes. But then another problem comes: backslashes that I specifically written were removed.

    It seems that the wpautop function is used for auto-formatting p tags. Since I’m hand-coding my posts’ HTML and know how to close my p’s, the best solution for me is to disable wpautop on my posts by disabling the following line in wp-includes/default-filters.php:

    add_filter(‘the_content’, ‘wpautop’);

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘pre tag shows slashes, code doesn’t?!’ is closed to new replies.