WordPress.org

Support

Support » How-To and Troubleshooting » Stop < code > tags wrapped with < p > tags

Stop < code > tags wrapped with < p > tags

  • Hi,
    I just downloaded and I’m very impressed. Been trying it out and I encountered a problem with the way it wraps < -code- > tags in < -p- > tags in the comments. The problem is do to the fact that inside the code tags themselves, if there is a newline, then a p tag is inserted so the end result in the parsed html output is a p wrap around the code tag with p tags inside the code tag. This obviously won’t validate as you can’t have a p tag in another p tag.
    I would like to know where in the files I can change it so that there is no p tag wrap around the code tag.
    Thanks
    -xDev

Viewing 10 replies - 1 through 10 (of 10 total)
  • It’s in wp-includes/functions.php (functions-formatting.php in recent nightlies) – the function wpautop. Good luck, and let us know what you do to it: I know how to fix it in a different approach to autopeeing, but I can’t quite see where and how in that approach.

    What version? wpautop() has undergone some revisions lately that may help.

    Don’t know if this is a possible solution, but what about using < pre > instead of < code >?
    Craig.

    pre is problematic with wpautop. There’s an alternative version of wpautop here. Try it out and see if it helps.

    Looks good to me, at first glance. Just have to remember to do <pre></pre> instead of the other way around (I forget which way I do it about every other time). Plus besides being a good idea, $split_pee is an excellent variable name 🙂

    Just a test:

    function balanceTags($text, $is_comment = 0) {
    global $use_balanceTags;
    if ($is_comment) {
    $text = sanitise_html_attributes($text);
    }
    if ($use_balanceTags == 0) {
    return $text;
    }
    $tagstack = array();
    $stacksize = 0;
    $tagqueue = '';
    $newtext = '';

    I want to look at the source to see how it was parsed.

    FYI: This post is similar…

    Well, what works for me is using <pre>the code<pre> (with the version of wpautop from cyberhobo). Since 's an inline element, I don't much want to just throw it in with a bunch of paragraphs, only contained by the outer <div>, and the whitespace is either significant (for Python) or at least aesthetically significant (cf. ten million holy wars about tabs v. spaces), so <pre> makes semantic sense to me at least.

    Wrapping code in pre may be alright for an admin posting an entry but I’m talking about comments. I don’t think it would work telling people to do that when they want to post some code. So the way things are right now my pages won’t validate if I use wordpress because of comments with p tags inside code tags and in some cases it breaks the layout. I thought the whole selling point is this:

    We have gone to great lengths to make sure every bit of WordPress generated code is in full compliance with the standards of the W3C.

    Ah, I read right past “in the comments”. <span style=”voice-family:Latella”>Nevermind.</span>.
    I do know people who run their submitted comments through a locally-installed validator, and throw GIGO errors from their autoparagraphing back at the user, but it’s not very popular.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Stop < code > tags wrapped with < p > tags’ is closed to new replies.