]>
git.bts.cx Git - cx.git/blob - cx/lib/markdown.php
771b9476370ed2546633eabdf9aea85454e87d8d
3 cx_require('lib', 'images.php');
4 cx_require('lib', 'url.php');
5 cx_require('third_party', 'parsedown', 'Parsedown.php');
7 class ExtendedParsedown
extends Parsedown
{
8 public function __construct() {
9 $this->InlineTypes
['{'][] = 'BlogImage';
10 $this->InlineTypes
['{'][] = 'Youtube';
11 $this->inlineMarkerList
.= '{';
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);
23 $permalink = '/data/images/' . $image->url
;
26 'extent' => strlen($matches[0]) +
1,
29 'attributes' => array(
30 'src' => cx_url_site($permalink),
31 'alt' => $image->alt_text
,
38 protected function inlineYoutube($excerpt) {
39 if (preg_match('/^{yt:([^}]+)}/', $excerpt['text'], $matches)) {
40 $video_id = $matches[1];
42 if ($video_id == null) {
47 'extent' => strlen($matches[0]) +
1,
51 'attributes' => array(
53 'type' => "text/html",
56 'src' => "https://www.youtube.com/embed/" . $video_id,
59 'referrerpolicy' => "no-referrer",
60 'sandbox' => "allow-same-origin allow-scripts",
68 function cx_markdown_generate_html($markdown) {
69 static $Parsedown = new ExtendedParsedown();
70 return $Parsedown->text($markdown);