content = $content; } public function execute() { return $this->handleParagraphs($this->content); } protected function handleParagraphs(array $paragraphs, $depth = 1) { $content = ''; foreach ($paragraphs as $paragraph) { $content = $content . str_repeat('#', $depth) . ' ' . (isset($paragraph['numbering']) ? $paragraph['numbering'] : '') . ' ' . $this->parseContent($paragraph['content']) . "\n"; if ( array_key_exists('children', $paragraph) && $paragraph['children'] && is_array($paragraph['children']) ) { $childrenContent = $this->handleParagraphs($paragraph['children'], $depth + 1); $content = $content . $childrenContent; } } return $content; } protected function parseContent($content) { $content = preg_replace("/\xE2\x80\x8B/", "", $content); $content = preg_replace("/[\x{200B}-\x{200D}\x{FEFF}]/u", "", $content); return utf8_decode($content); } }