ponepaste/includes/Pastedown.php

115 lines
3.6 KiB
PHP
Raw Permalink Normal View History

<?php
namespace PonePaste;
use ParsedownExtra;
class Pastedown extends ParsedownExtra {
public function __construct() {
2023-05-29 11:13:32 -04:00
parent::__construct();
unset($this->BlockTypes['>']);
2023-05-29 11:13:32 -04:00
$this->BlockTypes['>'] = ['Greentext'];
$this->InlineTypes['>'] = ['Greentext'];
2023-05-27 12:00:03 -04:00
array_unshift($this->InlineTypes['<'], 'Redtext');
2023-05-29 11:13:32 -04:00
$this->BlockTypes['<'] = ['Redtext'];
$this->InlineTypes['@'] = ['Purpletext'];
2023-05-29 11:13:32 -04:00
$this->BlockTypes['@'] = ['Purpletext'];
}
protected function inlineGreentext($Line)
{
2023-05-29 11:13:32 -04:00
if (preg_match('/^>[ ]?(.*)/', $Line['text'], $matches)) {
return [
'extent' => strlen($matches[0]),
'element' => [
'name' => 'span',
'handler' => 'line',
'text' => '&gt;' . $matches[1], // This is a huge hack to prevent recursive parsing
'attributes' => [
'class' => 'greentext'
]
]
];
}
}
2023-05-29 11:13:32 -04:00
protected function blockGreentext($Line)
{
if (preg_match('/^>[ ]?(.*)/', $Line['text'], $matches)) {
return [
'extent' => strlen($matches[0]),
'element' => [
'name' => 'div',
'handler' => 'line',
'text' => '&gt;' . $matches[1], // This is a huge hack to prevent recursive parsing
'attributes' => [
'class' => 'greentext'
]
]
];
}
}
protected function inlineRedtext($Line)
{
2023-05-29 11:13:32 -04:00
if (preg_match('/^<[ ]?(.*)/', $Line['text'], $matches)) {
return [
'extent' => strlen($matches[0]),
'element' => [
'name' => 'span',
'handler' => 'line',
'text' => '&lt;' . $matches[1], // This is a huge hack to prevent recursive parsing
'attributes' => [
'class' => 'redtext'
]
]
];
}
}
2023-05-29 11:13:32 -04:00
protected function blockRedtext($Line)
{
if (preg_match('/^<[ ]?(.*)/', $Line['text'], $matches)) {
return [
'extent' => strlen($matches[0]),
'element' => [
'name' => 'div',
'handler' => 'line',
'text' => '&lt;' . $matches[1], // This is a huge hack to prevent recursive parsing
'attributes' => [
'class' => 'redtext'
]
]
];
}
}
protected function inlinePurpletext($Line)
{
2023-05-29 11:13:32 -04:00
throw new \Exception("Calling the functor");
if (preg_match('/^@[ ]?(.*)/', $Line['text'], $matches))
{
2023-05-29 11:13:32 -04:00
return [
2023-05-27 17:34:01 -04:00
'markup' => "<div class=\"purpletext\">" . pp_html_escape($matches[0]) . "</div>",
2023-05-29 11:13:32 -04:00
'extent' => strlen($matches[0]),
'text' => $matches[1]
];
}
}
2023-05-29 11:13:32 -04:00
protected function blockPurpletext($Line)
{
if (preg_match('/^@[ ]?(.*)/', $Line['text'], $matches)) {
return [
'extent' => strlen($matches[0]),
'element' => [
'name' => 'div',
'handler' => 'line',
'text' => '&#64;' . $matches[1], // This is a huge hack to prevent recursive parsing
'attributes' => [
'class' => 'purpletext'
]
]
];
}
}
}