]> git.bts.cx Git - cx.git/blob - cx/lib/markdown.php
Try to fix aspect ratio issues
[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->InlineTypes['{'][] = 'Youtube';
11 $this->inlineMarkerList .= '{';
12 }
13
14 protected function inlineBlogImage($excerpt) {
15 if (preg_match('/^{img:([^}]+)}/', $excerpt['text'], $matches)) {
16 $image_id = $matches[1];
17 $image = cx_images_find_image($image_id);
18
19 if ($image == null) {
20 return;
21 }
22
23 $permalink = '/data/images/' . $image->url;
24
25 return array(
26 'extent' => strlen($matches[0]) + 1,
27 'element' => array(
28 'name' => 'img',
29 'attributes' => array(
30 'src' => cx_url_site($permalink),
31 'alt' => $image->alt_text,
32 ),
33 ),
34 );
35 }
36 }
37
38 protected function inlineYoutube($excerpt) {
39 if (preg_match('/^{yt:([^}]+)}/', $excerpt['text'], $matches)) {
40 $video_id = $matches[1];
41
42 if ($video_id == null) {
43 return;
44 }
45
46 return array(
47 'extent' => strlen($matches[0]) + 1,
48 'element' => array(
49 'name' => 'iframe',
50 'text' => '',
51 'attributes' => array(
52 'class' => "video",
53 'type' => "text/html",
54 //'width' => "640",
55 //'height' => "360",
56 'src' => "https://www.youtube.com/embed/" . $video_id,
57 'frameborder' => "0",
58 'loading' => "lazy",
59 'referrerpolicy' => "no-referrer",
60 'sandbox' => "allow-same-origin allow-scripts",
61 ),
62 ),
63 );
64 }
65 }
66 }
67
68 function cx_markdown_generate_html($markdown) {
69 static $Parsedown = new ExtendedParsedown();
70 return $Parsedown->text($markdown);
71 }