michelf / php-markdown

Parser for Markdown and Markdown Extra derived from the original Markdown.pl by John Gruber.
http://michelf.ca/projects/php-markdown/
Other
3.42k stars 529 forks source link

Small Issue With PHP Markdown (Extra) On Twenty Thirteen WordPress theme #73

Closed aahan closed 11 years ago

aahan commented 11 years ago

In WordPress' upcoming flagship theme "Twenty Thirteen" there's this code in functions.php:

function twentythirteen_aside_date( $content ) {
    if ( ! is_feed() && has_post_format( 'aside' ) ) {
        $content .= twentythirteen_entry_date( false );
    }
    return $content;
}
add_filter( 'the_content', 'twentythirteen_aside_date', 8 ); // After embeds, before everything else.

What it does is add entry date to aside posts after the content. For example, like this (live preview):

<div class="entry-content">
    <p>

        Here’s a pitch for a sequel to The Big Lebowski: <em>The Little Lebowski</em>, which&nbsp;follows the love-child of Maude and The Dude. I’d watch that, and I’d be dressed as a nihilist at the cinema.

        <span class="date"> HTML CODE FOR DATE HERE </span>

    </p>
</div>

The problem is, with PHP Markdown/Extra in place, the output is like this (live preview):

<div class="entry-content">
    <p>Here’s a pitch for a sequel to The Big Lebowski: <em>The Little Lebowski</em>, which&nbsp;follows the love-child of Maude and The Dude. I’d watch that, and I’d be dressed as a nihilist at the cinema.</p>

    <span class="date"> HTML CODE FOR DATE HERE </span>
</div>

That's right! The date is output outside the paragraph if PHP Markdown/Extra is enabled.

Changing this line in the function (which I mentioned above):

add_filter( 'the_content', 'twentythirteen_aside_date', 8 ); // After embeds, before everything else.

To this (changing priority to a number < 6):

add_filter( 'the_content', 'twentythirteen_aside_date', 5 );

Fixes the problem. But the comment for the line says, "After embeds, before everything else", it doesn't look like the theme should be modified, or it'd break something else.

Can something be changed in markdown.php? or is it something to be done within the theme itself? I am looking forward to some input from you.

michelf commented 11 years ago

You haven't said what it does when you change the priority of the twentythirteen_aside_date filter.

To me looks like the twentythirteen_aside_date function expects $content to not end with empty lines. What happens if you go edit your post so there's no empty line after the content?

Anyway, maybe I'm missing something, but the way this works seem pretty fragile and dependent on how Wordpress processes text in its default configuration. I don't think there is a way to make it work without changing the theme, at least not without hard-coding in markdown.php or in another filter a regular expression that detects a <span class="date"> and fix things for that special case.

aahan commented 11 years ago

To me looks like the twentythirteen_aside_date function expects $content to not end with empty lines. What happens if you go edit your post so there's no empty line after the content?

Not it can't be that. I tried publishing the post with and without an empty line (I usually don't place an empty line at the end of a post), and the issue persists.

You haven't said what it does when you change the priority of the twentythirteen_aside_date filter.

Like I said, it fixes the problem, i.e., the output is the way it should be:

<div class="entry-content">
    <p>

        Here’s a pitch for a sequel to The Big Lebowski: <em>The Little Lebowski</em>, which&nbsp;follows the love-child of Maude and The Dude. I’d watch that, and I’d be dressed as a nihilist at the cinema.

        <span class="date"> HTML CODE FOR DATE HERE </span>

    </p>
</div>

@michelf The so problem seems to be that the function in the theme that I am talking about, needs to execute before PHP Markdown plugin does, and that's not happening because you set the priority to 6 in markdown.php. Does that make any sense?

Also, I was wondering what blogging platform you use. It doesn't look like WordPress.

michelf commented 11 years ago

According to my (probably outdated) schematics of how PHP Markdown reshapes Wordpress's text system (it needs to move a couple of filters around so that Wordpress does not interfere with the syntax, details here), you need to put the Markdown filter pretty much before everything else. In this case, twentythirteen_aside_date needs to be done prior Markdown. But twentythirteen_aside_date must be done after embeds (according to the comment) while Markdown should be before embeds. There's no good solution to this cyclic dependency other than to "fix" twentythirteen_aside_date so it can work after Markdown.

You're right, my blog doesn't use Wordpress. I use a custom thing for my blog (and the rest of my site) built on top of Piecrust.

aahan commented 11 years ago

Okay. Two good plugins I know use PHP Markdown. I'll share the issue with the authors on the support forums and see if they can help. (I'll post back if I have some news.) Thanks for your time Michel!

michelf commented 11 years ago

Closing this issue since it seems nothings remain to do here.

aahan commented 11 years ago

Yep. Didn't receive any reply from devs who maintain markdown plugins for WordPress, so it's best to keep the issue closed until I can get more info.