Skip to content

Instantly share code, notes, and snippets.

@jtojnar
Last active August 29, 2015 14:13
Show Gist options
  • Save jtojnar/3a69cd23b1b57f699497 to your computer and use it in GitHub Desktop.
Save jtojnar/3a69cd23b1b57f699497 to your computer and use it in GitHub Desktop.
<?php
class ParsedownDetails extends ParsedownExtra {
function __construct() {
$this->BlockTypes['¡'][] = 'Details';
parent::__construct();
}
// Details
protected function blockDetails($Line) {
if (preg_match('/^([¡]{3,})[ ]*(.+)?[ ]*$/', $Line['text'], $matches)) {
$summary = [
'name' => 'summary',
'text' => 'Open spoiler by clicking',
];
if (isset($matches[2])) {
$summary['text'] = $matches[2];
}
$Block = [
'char' => $Line['text'][0],
'element' => [
'name' => 'details',
'handler' => 'elements',
'text' => [$summary, ''],
],
];
return $Block;
}
}
protected function blockDetailsContinue($Line, $Block) {
if (isset($Block['complete'])) {
return;
}
if (isset($Block['interrupted'])) {
$Block['element']['text'][1] .= "\n";
unset($Block['interrupted']);
}
if (preg_match('/^!{3,}[ ]*$/', $Line['text'])) {
$Block['element']['text'][1] = substr($Block['element']['text'][1], 1);
$Block['complete'] = true;
return $Block;
}
$Block['element']['text'][1] .= "\n".$Line['body'];
return $Block;
}
protected function blockDetailsComplete($Block) {
$Block['element']['text'][1] = $this->text($Block['element']['text'][1]);
return $Block;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment