WordPress.org

Making WordPress.org

Changeset 1138


Ignore:
Timestamp:
01/13/2015 07:55:39 PM (3 years ago)
Author:
coffee2code
Message:

developer.wordpress.org: Undo unintended markup generated by Markdown during parsing (namely, italics)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/formatting.php

    r1136 r1138  
    2727        add_filter( 'the_excerpt', array( __CLASS__, 'remove_inline_internal' ) );
    2828        add_filter( 'the_content', array( __CLASS__, 'remove_inline_internal' ) );
     29
     30        add_action( 'the_content', array( __CLASS__, 'fix_unintended_markdown' ) );
    2931    }
    3032
     
    165167    }
    166168
     169    /**
     170     * Fixes unintended markup generated by Markdown during parsing.
     171     *
     172     * The parser interprets underscores surrounding text as Markdown indicating
     173     * italics. That is never the intention, so undo it.
     174     *
     175     * @param  string      $content   The post content.
     176     * @param  null|string $post_type Optional. The post type. Default null.
     177     * @return string
     178     */
     179    public static function fix_unintended_markdown( $content, $post_type = null ) {
     180        // Only apply to parsed content that have the em tag.
     181        if ( DevHub\is_parsed_post_type( $post_type ) && false !== strpos( $content, '<em>' ) ) {
     182            $content = preg_replace_callback(
     183                '/([^\s])<em>(.+)<\/em>/',
     184                function ( $matches ) {
     185                    return $matches[1] . '_' . $matches[2] . '_';
     186                },
     187                $content
     188            );
     189        }
     190
     191        return $content;
     192    }
     193
    167194} // DevHub_Formatting
    168195
Note: See TracChangeset for help on using the changeset viewer.