This is not our friendly guide to using Markdown! If you’re only trying to format your show’s blurb, click here.


Camdram allows users to enter show descriptions as formatted text using Markdown. However, Markdown varies from implementation to implementation, and Camdram has to deal with legacy data, so this is not the whole story.

We use the Parsedown library to convert Markdown to HTML, alongside a few other techniques for legacy reasons.

The relevant PHP code (simplified from our TextService.php) is:

$markdown_regexs = array(
    '/\[L:(www\.[a-zA-Z0-9\.:\\/\_\-\?\&]+)\]/'          => '[$1](http://$1)',
    '/\[L:([a-zA-Z0-9\.:\\/\_\-\?\&]+)\]/'               => '$1',
    '/\[L:(www\.[a-zA-Z0-9\.:\\/\_\-\?\&]+);([^\]]+)\]/' => '[$2](http://$1)',
    '/\[L:([a-zA-Z0-9\.:\\/\_\-\?\&]+);([^\]]+)\]/'      => '[$2]($1)',
    '/\[E:([a-zA-Z0-9\.@\_\-]+)\]/'                      => '[$1](mailto:$1)',
    '/\[E:([a-zA-Z0-9\.@\_\-]+);([^\]]+)\]/'             => '[$2](mailto:$1)',
    '/\[L:mailto\:([a-zA-Z0-9\.@\_\-]+)\]/'              => '[$1](mailto:$1)',
    '/\[L:mailto\:([a-zA-Z0-9\.@\_\-]+);([^\]]+)\]/'     => '[$2](mailto:$1)',
    # Making the most common HTML work
    '/<\/?b>/'                                           => '**',
    '/<\/?i>/'                                           => '*',
    '/<br ?\/?>/'                                        => "\n",
    '/<hr ?\/?>/'                                        => "\n_______\n",
    # Enforce sensble header levels in user-submitted content.
    # h1 → h3, hn → h(n-1) for 2 ≤ n < 6.
    '/(?m)^(#{2,5}[^#])/'                                => "#$1",
    '/(?m)^#([^#])/'                                     => "###$1",
);

$this->parsedown = new Parsedown();
$this->parsedown->setSafeMode(true);
$this->parsedown->setBreaksEnabled(true);

// FYI: using strip_tags with both arguments is NOT a defence against XSS.
// We use Parsedown's safe mode to block harmful code.
$text = strip_tags($text, '<b><i><u><strong><em><p><ul><li><ol><br><green><red><pre><hr>');

$text = preg_replace(array_keys($this->markdown_regexs),
                     array_values($this->markdown_regexs), $text);
return $this->parsedown->text($text);

If you want to display properly formatted data from Camdram in your PHP application you can just use the above. In other languages, applying the regex list above followed by a GitHub-Flavoured markdown parser is likely to give perfectly acceptable results.

We are considering developing a script to convert Camdram Markdown to HTML using JavaScript in the future.