Recent Topics

[PLUGIN] Markdown comes to b2evo

Started by on Dec 18, 2004 – Contents updated: Dec 18, 2004

Dec 18, 2004 02:47    

I've developed a simple plugin so that b2evo users can write posts in Markdown syntax. Here's the plugin:

http://www.sims.berkeley.edu/~jhall/b2evo_markdown/

and here's more on markdown from John Gruber:

http://daringfireball.net/projects/markdown/

Dec 18, 2004 03:46

Got a link that works? The link in your post gives me what looks like an open directory with info about the plugin, but there is no way to get the plugin from the link in the top portion. The link following [plugin] : in the text (a pobox link) tells me "Unable to Complete Request". Can you save it as a .txt file and link to that, or maybe zip it up and link to the zip?

Dec 18, 2004 05:05

sorry... the link was broken as posted. Here's a direct link (don't access this directly, right-click save as):

http://www.sims.berkeley.edu/~jhall/b2evo_markdown/_markdown.renderer.php

this should work too (beyond when I leave Berkeley):

http://pobox.com/~joehall/b2evo_markdown/

Here is the code:

Code

<?php
 
/**
 
* This file implements John Gruber's Markdown language using Michel Fortin's PHP Markdown
 
*
 
* b2evolution - {@link http://b2evolution.net/}
 
* Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
 
* @copyright (c)2003-2004 by Francois PLANQUE - b2evolution - {@link http://fplanque.net/}
 
* @copyright (c)2004 by John Gruber - Markdown - {@link http://daringfireball.net/projects/markdown/}
 
* @copyright (c)2004 by Michel Fortin - PHP Markdown- {@link http://www.michelf.com/projects/php-markdown/}
 
* @copyright (c)2004 by Joseph Lorenzo Hall - b2evo renderer- {@link http://pobox.com/~joehall/}
 
*
 
* @package plugins
 
*/
 
if( !defined('DB_USER') ) die( 'Please, do not access this page directly.' );
 
 
 
/**
 
* Includes:
 
*/
 
require_once dirname(__FILE__).'/../renderer.class.php';
 
include_once "markdown.php";
 
 
 
/**
 
* @package plugins
 
*/
 
class markdown_Rendererplugin extends RendererPlugin
 
{
 
  var $code = 'b2evMrkdwn';
 
  var $name = 'Markdown';
 
  var $priority = 60;
 
 
 
  var $apply_when = 'opt-out';
 
  var $apply_to_html = true;
 
  var $apply_to_xml = false;
 
  var $short_desc;
 
  var $long_desc;
 
 
 
 
 
  /**
 
   * Constructor
 
   *
 
   * {@internal markdown_Rendererplugin::markdown_Rendererplugin(-)}}
 
   */
 
  function markdown_Rendererplugin()
 
  {
 
    $this->short_desc = T_('Parse Markdown syntax and make HTML');
 
    $this->long_desc = T_('No description available');
 
  }
 
 
 
 
 
  /**
 
   * Perform rendering
 
   *
 
   * {@internal markdown_Rendererplugin::render(-)}}
 
   *
 
   * @param string content to render (by reference) / rendered content
 
   * @param string Output format, see {@link format_to_output()}
 
   * @return boolean true if we can render something for the required output format
 
   */
 
  function render( & $content, $format )
 
  {
 
    if( ! parent::render( $content, $format ) )
 
    {  // We cannot render the required format
 
      return false;
 
    }
 
  
 
    $content = Markdown( $content );
 
    
 
    return true;
 
  }
 
}
 
 
 
// Register the plugin:
 
$this->register( new markdown_Rendererplugin() );
 
 
 
?>

Dec 18, 2004 15:23

Ok, two things on this.

1. Make a zip file for download with both your plugin and the markup.php file, and let the user know to extract both to their plugins/renderers dir for 'out of the box functionality'.

2. Since this creates paragraph tags automagically, you mighttell the users to disable auto-p plugin as I can't tell if this will have undesired side effects for posts. On my test with a single line there was no ill effects, but I'm not sure if things will be confused with many paragraph (EdB wordy) posts.

Other than that, looks like a good plugin. Nice job.

Dec 18, 2004 18:33

mattbta wrote:

1. Make a zip file for download with both your plugin and the markup.php file, and let the user know to extract both to their plugins/renderers dir for 'out of the box functionality'.

2. Since this creates paragraph tags automagically, you mighttell the users to disable auto-p plugin as I can't tell if this will have undesired side effects for posts. On my test with a single line there was no ill effects, but I'm not sure if things will be confused with many paragraph (EdB wordy) posts.

Done and done. The Zip file is here:

http://pobox.com/~joehall/b2evo_markdown/b2evo_markdown.zip

And by looking at the parent directory you should see the README file which tells users to disable all default plugins save "_autolinks.renderer.php":

http://pobox.com/~joehall/b2evo_markdown/

Finally, here's a post that uses the exact same syntax as the README file, but parsed via the plugin into HTML:

http://pobox.com/~joehall/nqb2/index.php/2004/12/17/b2evo_markdown

Jan 27, 2005 02:27

+1 putting this in default distro

Jan 27, 2005 22:19

Here's a version which works with the new plugin architecture in current CVS:

Code

<?php
/**
* This file implements John Gruber's Markdown language using Michel Fortin's PHP Markdown
*
* b2evolution - {@link http://b2evolution.net/}
* Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
* @copyright (c)2003-2004 by Francois PLANQUE - b2evolution - {@link http://fplanque.net/}
* @copyright (c)2004 by John Gruber - Markdown - {@link http://daringfireball.net/projects/markdown/}
* @copyright (c)2004 by Michel Fortin - PHP Markdown- {@link http://www.michelf.com/projects/php-markdown/}
* @copyright (c)2004 by Joseph Lorenzo Hall - b2evo renderer- {@link http://pobox.com/~joehall/}
*
* @package plugins
*/
if( !defined('DB_USER') ) die( 'Please, do not access this page directly.' );
 
/**
* Includes:
*/
include_once "markdown.php";
 
/**
* @package plugins
*/
class markdown_plugin extends Plugin
{
  var $code = 'b2evMrkdwn';
  var $name = 'Markdown';
  var $priority = 60;
 
  var $apply_when = 'opt-out';
  var $apply_to_html = true;
  var $apply_to_xml = false;
  var $short_desc;
  var $long_desc;
 
 
  /**
   * Constructor
   *
   * {@internal markdown_plugin::markdown_plugin(-)}}
   */
  function markdown_plugin()
  {
    $this->short_desc = T_('Parse Markdown syntax and make HTML');
    $this->long_desc = T_('No description available');
  }
 
 
  /**
   * Perform rendering
   *
   * {@internal markdown_plugin::Render(-)}}
   *
   * @param array Associative array of parameters
   *               (Output format, see {@link format_to_output()})
   * @return boolean true if we can render something for the required output format
   */
  function Render( & $params )
  {
    if( ! parent::Render( $params ) )
    {  // We cannot render the required format
      return false;
    }
    
    $content = & $params['data'];
    $content = Markdown( $content );
    
    return true;
  }
 
}
 
?>

Jul 25, 2006 14:07

How do I make this work for summer beta 1.8?

Oct 10, 2006 07:57

I'd also like to know this :-)

Has anyone updated this plugin for 1.8 or can someone outline the steps needed to get this to work?

Oct 10, 2006 20:50

Hi, I've implemented the PHP Markdown Extra from Michel Fortin as a plugin for b2evo.

It works with the latest version (1.8.2) and can be downloaded here:
http://bie.no/blog/?p=57

I needed to do Apply rendering: 'always' to get it to work properly .. let me know if I did something wrong ;)

- bjorn

Oct 11, 2006 07:58

haha, yeah I was wondering about that ;)

for those of you who don't know what we're talking about I submitted the form about three times but got a message that I was spamming ;)

- bjorn

Oct 11, 2006 08:13

@ bjornbjorn
Thanks for this.... I assume it for posting and cannot be applied to "comments" !

Oct 11, 2006 09:41

You want to use the FilterCommentContent hook ;)

Code

function FilterCommentContent( & $params )
  {
    return $this->RenderItemAsHtml( $params )
  }

¥

Oct 11, 2006 11:28

Thanks! :-)

I'll implement this as an optional setting as I don't think everyone would want Markdown enabled for comments.

Oct 11, 2006 12:11

I'll implement this as an optional setting as I don't think everyone would want Markdown enabled for comments.

Sounds good... look forward to it

Oct 11, 2006 19:02

Ok, I've updated the plugin to support comments as well.

It's disabled by default - so after install you will need to enable it in the plugin config.

enjoy :-)

Oct 11, 2006 19:44

@ bjornbjorn
I just downloaded it again and Winmerge picked up no differences. Is the original download URL the correct one for the updated files?

Oct 12, 2006 11:09

Sweet... does what it says on the label.
Thanks bjornbjorn


Form is loading...

multiblog platform – This forum is powered by b2evolution CMS, a complete engine for your website.