2 edb Dec 18, 2004 03:46

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:
<?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() );
?>
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.
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
+1 putting this in default distro
Here's a version which works with the new plugin architecture in current CVS:
<?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;
}
}
?>
How do I make this work for summer beta 1.8?
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?
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
http://bie.no/blog/products/2006/10/markdown-extra-plugin-for-b2evolution/
there ya go, bjornbjorn it was *products* that was getting caught, btw :)
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
@ bjornbjorn
Thanks for this.... I assume it for posting and cannot be applied to "comments" !
That's right, it currently only works for posts.
I guess that's because [url=http://doc.b2evolution.net/v-1-8/plugins/Plugin.html#RenderItemAsHtml]RenderItemAsHtml[/url] doesn't get called on comments.
Does comments call RenderItem()? - because then it would be pretty easy to make it work with comments as well...
You want to use the FilterCommentContent hook ;)
function FilterCommentContent( & $params )
{
return $this->RenderItemAsHtml( $params )
}
¥
Thanks! :-)
I'll implement this as an optional setting as I don't think everyone would want Markdown enabled for comments.
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
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 :-)
@ bjornbjorn
I just downloaded it again and Winmerge picked up no differences. Is the original download URL the correct one for the updated files?
ah, my bad, uploaded with wrong filename:
Here's the file:
http://www.bie.no/products/b2evo_markdown_extra.zip
Instructions if needed:
http://www.bie.no/blog/?p=57
- bjorn
Sweet... does what it says on the label.
Thanks bjornbjorn
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?