srEscape = $escape; $this->srPrefix = $content; return $this; } /** * @param string $text - text to show * @param int $thresholdLength - mb_character length that triggers the collapsible behavior; choose experimentally * @param string $maxHeight - max height CSS value (e.g. 8em) */ public function __construct($text, $thresholdLength, $maxHeight) { $this->text = $text; $this->collapsing = mb_strlen($text) > $thresholdLength; $this->maxHeight = $maxHeight; } private function processText($t) { $out = e($t); $out = str_replace("\r\n", "\n", $out); $out = '
'.str_replace("\n\n", "
". '', $out).'
'; $out = nl2br($out); $out = preg_replace('|(https?://[^\s]+)|i', '\1', $out); return $out; } public function render() { $content = $this->processText($this->text); $prefix = ''; if ($this->srPrefix) { $prefix = ''. ($this->srEscape ? e($this->srPrefix) : $this->srPrefix). ' '; } if ($this->collapsing) { return '