1

I am trying to implement WMD onto my website and was wondering how would I go about running showdown.js server side to convert markdown to HTML? (in order to store both in the DB)

I am using PHP...any tips would be helpful (never ran any sort of js from php before)

Thanks, Andrew

Andrew
  • 3,650
  • 9
  • 31
  • 32

3 Answers3

4

You could use PHP Markdown, which is a port of the Markdown program written by John Gruber.

Here is a example of how to use PHP Markdown with your code.

include_once "markdown.php";
$my_html = Markdown($my_text);
stukelly
  • 4,257
  • 3
  • 37
  • 44
2

If you're going to run a markdown converter, why run the javascript port? Isn't that a bit backwards?

Markdown was originally designed to run server-side, showdown is a port that allows the conversion to happen in javascript.

Here is where you start.

tylerl
  • 30,197
  • 13
  • 80
  • 113
  • The original perl implementation is only one of many server-side implementations that exist. @stukelly pointed out a PHP port. – tylerl Apr 09 '09 at 01:47
0

WMD handles the client side implementation of your markup. It allows the user to see a rich text version of their input before they submit.

Once the user is happy, they send their input to the server using the form.

At this point you will use your PHP script to take the input and sanitise it. You will need to remove all the possible XSS exploits and any HTML tags which you do not want to store in your database.

Jon Winstanley
  • 23,010
  • 22
  • 73
  • 116
  • 3
    The issue is that using Markdown.js on the client side and running and different parser server side will produce inconsistent results given the engines will have subtle differences! – Mohamad Jan 05 '11 at 01:45