RobertPitt
RobertPitt

Reputation: 57268

Creating Simple markdown class

Im currently working on a system that has a comment system integrated, the system is running on Codeigniter so im looking to create a markdown library but with really minimal features.

The features im looking to have is

And that's practically it, The post data will be run through Codeigniter's XSS Class before it goes to the mark down class

So my question is what's the best way to do this, should i be using a library out there and disabling certain features, should I build this from scratch, if so, how should i build the class and what things should I take into account.

Upvotes: 2

Views: 1288

Answers (3)

dsp
dsp

Reputation: 111

For me the easiest way to integrate Markdown is by simply

  • putting markdown.php from Michel Fortrin into my Application/helpers/ folder,
  • rename it to markdown_helper.php
  • load it with $this->load->helper('markdown');

...just in case someone - like me - stumbles upon this old thread again :)

Upvotes: 2

Vamsi Krishna B
Vamsi Krishna B

Reputation: 11490

You can begin with PHP Markdown class ?

or the one for CI.

And If I may suggest, you can also try MarkItUp as front end..

Upvotes: 2

helloandre
helloandre

Reputation: 10721

I was in a similar situation recently, where I wanted to support some kind of markup (BB, Markdown, etc). It turns out nothing has been done with BBCode for about 100 years, and it's dead easy to write a regex parser for it (for well-formed markup at least) so i wrote a really bare bones function to do just that.

My version also includes images, codes, and color support as well as nested tags ([b][i]bold and italic[/i][/b]).

function parseBBCode($string){
    $search = array(
        '/\[b\](.*?)\[\/b\]/',
        '/\[i\](.*?)\[\/i\]/',
        '/\[u\](.*?)\[\/u\]/',
        '/\[img\](.*?)\[\/img\]/',
        '/\[url\=(.*?)\](.*?)\[\/url\]/',
        '/\[code\](.*?)\[\/code\]/',
        '/\[color\=(.*?)\](.*?)\[\/color\]/'
    );
    $replace = array(
        '<strong>\\1</strong>',
        '<em>\\1</em>',
        '<u>\\1</u>',
        '<img src="\\1">',
        '<a href="\\1" target="_blank">\\2</a>',
        '<code>\\1</code>',
        '<span style="color:\\1;">\\2</span>'
    );
    $new = preg_replace($search, $replace, $string);
    return nl2br($new);
}

Upvotes: 4

Related Questions