]> git.bts.cx Git - cx.git/blob - cx/lib/markdown.php
Basic admin styling
[cx.git] / cx / lib / markdown.php
1 <?php
2
3 cx_require('lib', 'images.php');
4 cx_require('lib', 'url.php');
5 cx_require('third_party', 'parsedown', 'Parsedown.php');
6
7 class ExtendedParsedown extends Parsedown {
8 public function __construct() {
9 $this->InlineTypes['{'][]= 'BlogImage';
10 $this->inlineMarkerList .= '{';
11 }
12
13 protected function inlineBlogImage($excerpt) {
14 if (preg_match('/^{img:([^}]+)}/', $excerpt['text'], $matches)) {
15 $image_id = $matches[1];
16 $image = cx_images_find_image($image_id);
17
18 if ($image == null) {
19 return;
20 }
21
22 $permalink = '/data/images/' . $image->url;
23
24 return array(
25 'extent' => strlen($matches[0]) + 1,
26 'element' => array(
27 'name' => 'img',
28 'attributes' => array(
29 'src' => cx_url($permalink),
30 'alt' => $image->alt_text,
31 ),
32 ),
33 );
34 }
35 }
36 }
37
38 function cx_markdown_generate_html($markdown) {
39 static $Parsedown = new ExtendedParsedown();
40 return $Parsedown->text($markdown);
41 }