milohuang / reverie

Reverie is a versatile HTML5 responsive WordPress framework based on ZURB's Foundation.
http://theakiba.com/reverie/
MIT License
918 stars 196 forks source link

Auto-wrapping images with <figure> tag buggy #248

Open nickbouton opened 10 years ago

nickbouton commented 10 years ago

Seems to be present in both Reverie 4 & 5 as the reverie_img_unautop() function in clean.php has not changed.

Probably an issue with the regex being too greedy, but if you place an image inside a regular content paragraph with alignleft, alignright, or aligncenter, the resulting <figure> tag expands around the next paragraph (or more) of text as well, not just the image, and doesn't close properly until the end of the entry content.

Stopgap fix is to remove the reverie_img_unautop() function altogether.

nickbouton commented 10 years ago

Updating the body of reverie_img_unautop() to look for XHTML-valid <img /> tags seems to do the trick of handling images wrapped in <p></p> tags but not catching regular images aligned inside of content blocks (which don't need the preprocessing), FWIW.

Probably not perfect as HTML5 allows non-self-closing tags, but works for me as a temporary replacement:

function reverie_img_unautop($pee) {
    return preg_replace('/<p>\\s*?(<a .*?><img.*?\/><\\/a>|<img.*?\/>)?\\s*<\\/p>/s',
        '<figure class="figure">$1</figure>', $pee);
}