simple = $simple;
$this->no_markup = true;
$this->span_gamut += ['doSpoilers' => 71];
$this->span_gamut += ['doSearchPermalinks' => 72];
$this->span_gamut += ['doStrike' => 6];
$this->span_gamut += ['doUsers' => 7];
$this->span_gamut += ['doPosts' => 8];
$this->span_gamut += ['doTags' => 9];
$this->span_gamut += ['doAutoLinks2' => 29];
//fix italics/bold in the middle of sentence
$prop = ['em_relist', 'strong_relist', 'em_strong_relist'];
for ($i = 0; $i < 3; $i ++)
{
$this->{$prop[$i]}[''] = '(?:(?{$prop[$i]}[str_repeat('*', $i + 1)] = '(?<=\S|^)(?{$prop[$i]}[str_repeat('_', $i + 1)] = '(?<=\S|^)(?simple)
{
$text = preg_replace('/\A\n+|\n+\z/', '', $text);
$grafs = preg_split('/\n{2,}/', $text, -1, PREG_SPLIT_NO_EMPTY);
foreach ($grafs as $key => $value)
{
if (!preg_match('/^B\x1A[0-9]+B$/', $value))
{
$value = $this->runSpanGamut($value);
$grafs[$key] = $this->unhash($value);
}
else
{
$grafs[$key] = $this->html_hashes[$value];
}
}
return implode("\n\n", $grafs);
}
return parent::formParagraphs($text);
}
public static function simpleTransform($text)
{
$parser = new self(true);
return $parser->transform($text);
}
//automatically form links out of http://(...) and www.(...)
protected function doAutoLinks2($text)
{
$text = preg_replace_callback('{(?<\s(){}]+)}i', [&$this, '_doAutoLinks_url_callback'], $text);
$text = preg_replace_callback('{(?<\s(){}]+)}i', [&$this, '_doAutoLinks_url_callback'], $text);
return $text;
}
//extend anchors callback for doAutolinks2
protected function _doAnchors_inline_callback($matches)
{
if ($matches[3] == '')
$url = &$matches[4];
else
$url = &$matches[3];
if (!preg_match('/^((https?|ftp):|)\/\//', $url))
$url = 'http://' . $url;
return parent::_doAnchors_inline_callback($matches);
}
//handle white characters inside code blocks
//so that they won't be optimized away by prettifying HTML
protected function _doCodeBlocks_callback($matches) {
$codeblock = $matches[1];
$codeblock = $this->outdent($codeblock);
$codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES);
$codeblock = preg_replace('/\A\n+|\n+\z/', '', $codeblock);
$codeblock = preg_replace('/\n/', '
', $codeblock);
$codeblock = preg_replace('/\t/', '&tab;', $codeblock);
$codeblock = preg_replace('/ /', ' ', $codeblock);
$codeblock = "
$codeblock\n
";
return "\n\n".$this->hashBlock($codeblock)."\n\n";
}
//change hard breaks trigger - simple \n followed by text
//instead of two spaces followed by \n
protected function doHardBreaks($text)
{
return preg_replace_callback('/\n(?=[\[\]\(\)\w])/', [&$this, '_doHardBreaks_callback'], $text);
}
protected function doStrike($text)
{
return preg_replace_callback('{(~~|---)([^~]+)\1}', function($x)
{
return $this->hashPart('