misuzu/src/Parsers/MarkdownParser.php

47 lines
1.3 KiB
PHP
Raw Normal View History

2018-05-24 21:31:48 +02:00
<?php
namespace Misuzu\Parsers;
use Parsedown;
2019-06-10 19:04:53 +02:00
class MarkdownParser extends Parsedown implements ParserInterface {
public function parseText(string $text): string {
2018-07-15 04:15:12 +02:00
return $this->text($text);
2018-05-24 21:31:48 +02:00
}
2019-06-10 19:04:53 +02:00
public function parseLine(string $line): string {
2018-07-15 04:15:12 +02:00
return $this->line($line);
2018-05-24 21:31:48 +02:00
}
2019-01-03 02:43:12 +01:00
2019-06-10 19:04:53 +02:00
protected function inlineImage($excerpt) {
2023-01-26 22:51:33 +00:00
// remove this line when media detection works entirely as expected
return parent::inlineImage($excerpt);
2023-01-26 22:51:33 +00:00
if(!isset($excerpt['text'][1]) || $excerpt['text'][1] !== '[')
return;
2023-01-26 22:51:33 +00:00
$excerpt['text'] = substr($excerpt['text'], 1);
$link = $this->inlineLink($excerpt);
if($link === null)
return;
$inline = [
'extent' => $link['extent'] + 1,
'element' => [
'name' => 'span',
'attributes' => [
'class' => 'js-msz-embed-media',
'data-msz-embed-url' => $link['element']['attributes']['href'],
'data-msz-embed-alt' => $link['element']['text'],
],
],
];
$inline['element']['attributes'] += $link['element']['attributes'];
unset($inline['element']['attributes']['href']);
return $inline;
2019-01-03 02:43:12 +01:00
}
2018-05-24 21:31:48 +02:00
}