user4446130
user4446130

Reputation:

How would I implement a StackOverflow-like Markdown in PHP?

What am I looking for?

I am looking for a markdown language that works similiar to the one used here on stackoverflow.

Possible solutions

I could go and write my own Markup language but I think this will be a waste of time. This is a possibility though.

What I really want to know is if the StackOverflow markdown language is opensource or if there are similiar opensource packages available for use in PHP.

Upvotes: 1

Views: 118

Answers (1)

RedGrittyBrick
RedGrittyBrick

Reputation: 4002

Markdown Implementation

You should look for an already existing library that you can plug in and use.

Firstly you need to decide between two major groups of markdown implementations

  • basic
  • extended (tables etc)

Stackexchange uses what I would call basic or original markdown.

Some search terms you should explore:

  • Basic
    • John Gruber Markdown
    • CommonMark
    • PHP Markdown
  • Extended
    • Fletcher Penney MultiMarkdown
    • PHP Markdown Extra
    • PHP MultiMarkdown
    • PHP Parsedown

I use PHP Parsedown. I find it effective but a bit quirky and intolerant.

You should note that the Markdown definition is very fractured, apart from CommonMark the markup used by the original and other implementations isn't well-defined and so different implementations will often produce different results and support different features.

Security

There are some security concerns. Markdown accessible to end-users allows them to insert arbitrary HTML which can introduce cross-site scripting and other security problems. You may need to pre-process the markup or post-process the HTML to remove problematic elements. Stackexchange allows only a limited subset of HTML for this reason.

Upvotes: 2

Related Questions