Closed #9
This commit is contained in:
parent
91776a3e54
commit
fa652c2fca
3 changed files with 62 additions and 1 deletions
|
@ -320,3 +320,21 @@ pre.debug {
|
|||
text-align: left;
|
||||
color: black;
|
||||
}
|
||||
|
||||
.spoiler:before,
|
||||
.spoiler:after {
|
||||
color: gray;
|
||||
}
|
||||
.spoiler:before {
|
||||
content: '[ ';
|
||||
}
|
||||
.spoiler:after {
|
||||
content: ' ]';
|
||||
}
|
||||
.spoiler {
|
||||
background: #eee;
|
||||
color: #eee;
|
||||
}
|
||||
.spoiler:hover {
|
||||
color: black;
|
||||
}
|
||||
|
|
42
src/CustomMarkdown.php
Normal file
42
src/CustomMarkdown.php
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
class CustomMarkdown extends \Michelf\Markdown
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->no_markup = true;
|
||||
$this->span_gamut += ['doSpoilers' => 71];
|
||||
$this->span_gamut += ['doPosts' => 8];
|
||||
$this->span_gamut += ['doTags' => 9];
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function doHardBreaks($text)
|
||||
{
|
||||
return preg_replace_callback('/\n/', array(&$this, '_doHardBreaks_callback'), $text);
|
||||
}
|
||||
|
||||
protected function doSpoilers($text)
|
||||
{
|
||||
if (is_array($text))
|
||||
{
|
||||
$text = $this->hashPart('<span class="spoiler">') . $text[1] . $this->hashPart('</span>');
|
||||
}
|
||||
return preg_replace_callback('{\[spoiler\]((?:[^\[]|\[(?!\/?spoiler\])|(?R))+)\[\/spoiler\]}is', [__CLASS__, 'doSpoilers'], $text);
|
||||
}
|
||||
|
||||
protected function doPosts($text)
|
||||
{
|
||||
return preg_replace_callback('/@(\d+)/', function($x)
|
||||
{
|
||||
return $this->hashPart('<a href="' . \Chibi\UrlHelper::route('post', 'view', ['id' => $x[1]]) . '">') . $x[0] . $this->hashPart('</a>');
|
||||
}, $text);
|
||||
}
|
||||
|
||||
protected function doTags($text)
|
||||
{
|
||||
return preg_replace_callback('/#([a-zA-Z0-9_-]+)/', function($x)
|
||||
{
|
||||
return $this->hashPart('<a href="' . \Chibi\UrlHelper::route('post', 'list', ['query' => $x[1]]) . '">') . $x[0] . $this->hashPart('</a>');
|
||||
}, $text);
|
||||
}
|
||||
}
|
|
@ -144,6 +144,7 @@ class TextHelper
|
|||
|
||||
public static function parseMarkdown($text)
|
||||
{
|
||||
return \Michelf\Markdown::defaultTransform($text);
|
||||
#$text = strip_tags($text);
|
||||
return CustomMarkdown::defaultTransform($text);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue