WordPress.org

Plugin Directory

Changeset 488246


Ignore:
Timestamp:
01/11/12 16:06:20 (2 years ago)
Author:
mattwiebe
Message:
  • Favour Markdown formatting in all cases, turn off wpautop. Ensures that paragraphs and line breaks are handled according to the Markdown documentation.
  • Maintain oEmbed auto-embedding
Location:
markdown-on-save-improved/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • markdown-on-save-improved/trunk

  • markdown-on-save-improved/trunk/markdown-on-save.php

    r487889 r488246  
    33Plugin Name: Markdown on Save Improved 
    44Description: Allows you to compose content in Markdown on a per-item basis from WP admin or mobile/3rd-party apps. The markdown version is stored separately, so you can deactivate this plugin and your posts won't spew out Markdown. Based on <a href="http://wordpress.org/extend/plugins/markdown-osi/">Mark Jaquith's plugin</a>. 
    5 Version: 2.0.1 
     5Version: 2.1 
    66Author: Matt Wiebe 
    77Author URI: http://somadesign.ca/ 
     
    1010 
    1111/* 
    12  * Copyright 2011 Matt Wiebe. 
     12 * Copyright 2011-12 Matt Wiebe. 
    1313 * 
    1414 * This software is forked from the original Markdown on Save plugin (c) Mark Jaquith 
     
    3636        add_action( 'load-post.php', array( $this, 'load' ) ); 
    3737        add_action( 'load-post-new.php', array( $this, 'load') ); 
     38        remove_action( 'the_content', 'wpautop' ); 
     39        // Markdown breaks autoembedding by wrapping URLs on their own line in paragraphs 
     40        if ( get_option('embed_autourls') ) 
     41            add_filter( 'the_content', array($this, 'oembed_fixer'), 8 ); 
    3842    } 
    3943     
     
    111115    } 
    112116     
     117    /** 
     118     * Fixes oEmbed auto-embedding of single-line URLs 
     119     *  
     120     * WP's normal autoembed assumes that there's no <p>'s yet because it runs before wpautop 
     121     * But, when running Markdown, we have <p>'s already there, including around our single-line URLs 
     122     */ 
     123    public function oembed_fixer($content) { 
     124        global $wp_embed; 
     125        return preg_replace_callback( '|^\s*<p>(https?://[^\s"]+)</p>\s*$|im', array($wp_embed, 'autoembed_callback'), $content ); 
     126    } 
     127     
    113128    protected function html_to_markdown($content) { 
    114129        $content = stripslashes($content); 
     
    125140        // Stripslashes would lose desired backslashes. So, regex. 
    126141        $content = preg_replace( '/\\\"/', '"', $content ); 
    127         // convert to Markdown, but remove <p> tags for wpautop to work later 
    128         $content = $this->unp( Markdown( $content ) ); 
     142        // convert to Markdown 
     143        $content = Markdown( $content ); 
    129144        // reference the post_id to make footnote ids unique 
    130145        $content = preg_replace('/fn(ref)?:/', "fn$1-$id:", $content); 
     
    150165    } 
    151166 
    152     private function unp( $content ) { 
    153         return preg_replace( "#<p>(.*?)</p>(\n|$)#", '$1$2', $content ); 
    154     } 
    155  
    156167    private function is_markdown( $id ) { 
    157168        return ! get_post_meta( $id, self::PM, true ); 
  • markdown-on-save-improved/trunk/readme.txt

    r487889 r488246  
    44Requires at least: 3.2 
    55Tested up to: 3.3 
    6 Stable tag: 2.0.1 
     6Stable tag: 2.1 
    77 
    88Markdown + WordPress = writing bliss. The markdown version is stored separately, so you can deactivate this plugin and your posts won't spew out Markdown. 
     
    5858== Changelog == 
    5959 
     60= 2.1 = 
     61 
     62* Favour Markdown formatting in all cases, turn off wpautop. Ensures that paragraphs and line breaks are handled according to the [Markdown documentation](http://daringfireball.net/projects/markdown/syntax#p). 
     63* Maintain oEmbed auto-embedding 
     64 
    6065= 2.0.1 = 
    6166 
Note: See TracChangeset for help on using the changeset viewer.