WordPress.org

Ready to get started?Download WordPress

Forums

Stop < code > tags wrapped with < p > tags (11 posts)

  1. xDev
    Member
    Posted 10 years ago #

    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

  2. philor
    Member
    Posted 10 years ago #

    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.

  3. Ryan Boren
    WordPress Dev
    Posted 10 years ago #

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

  4. NuclearMoose
    Member
    Posted 10 years ago #

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

  5. Ryan Boren
    WordPress Dev
    Posted 10 years ago #

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

  6. philor
    Member
    Posted 10 years ago #

    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 :)

  7. xDev
    Member
    Posted 10 years ago #

    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.

  8. MathiasBynens
    Member
    Posted 10 years ago #

    FYI: This post is similar...

  9. philor
    Member
    Posted 10 years ago #

    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.

  10. xDev
    Member
    Posted 10 years ago #

    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.

  11. philor
    Member
    Posted 10 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.